Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r413ad05 r8cc5cb0  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 26 16:45:44 2016
    13 // Update Count     : 1964
     12// Last Modified On : Thu Aug 11 18:02:57 2016
     13// Update Count     : 1861
    1414//
    1515
     
    4343#define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time
    4444#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
     45extern char *yytext;
    4546
    4647#undef __GNUC_MINOR__
     
    5556#include "LinkageSpec.h"
    5657
    57 extern DeclarationNode * parseTree;
    58 extern LinkageSpec::Spec linkage;
    59 extern TypedefTable typedefTable;
    60 
    61 std::stack< LinkageSpec::Spec > linkageStack;
    62 
    63 void appendStr( std::string *to, std::string *from ) {
     58DeclarationNode *theTree = 0;                                                   // the resulting parse tree
     59LinkageSpec::Type linkage = LinkageSpec::Cforall;
     60std::stack< LinkageSpec::Type > linkageStack;
     61TypedefTable typedefTable;
     62
     63void appendStr( std::string &to, std::string *from ) {
    6464        // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
    65         to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
     65        to.insert( to.length() - 1, from->substr( 1, from->length() - 2 ) );
    6666} // appendStr
    6767%}
     
    126126        InitializerNode *in;
    127127        OperKinds op;
    128         std::string *str;
    129128        bool flag;
    130129}
     
    132131%type<tok> identifier  no_01_identifier  no_attr_identifier zero_one
    133132%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  no_01_identifier_or_type_name
    134 %type<constant> string_literal
    135 %type<str> string_literal_list
     133%type<constant> string_literal_list
    136134
    137135// expressions
     
    145143%type<en> constant_expression                   assignment_expression           assignment_expression_opt
    146144%type<en> comma_expression                              comma_expression_opt
     145//%type<en> argument_expression_list            argument_expression                     for_control_expression          assignment_opt
    147146%type<en> argument_expression_list              argument_expression                     assignment_opt
    148147%type<fctl> for_control_expression
     
    163162%type<sn> case_value_list                               case_label                                      case_label_list
    164163%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    165 %type<sn> handler_list                                  handler_clause                          finally_clause
     164%type<pn> handler_list                                  handler_clause                          finally_clause
    166165
    167166// declarations
     
    225224%type<decl> paren_identifier paren_type
    226225
    227 %type<decl> storage_class storage_class_list
     226%type<decl> storage_class storage_class_name storage_class_list
    228227
    229228%type<decl> sue_declaration_specifier sue_type_specifier
     
    298297
    299298push:
    300                 { typedefTable.enterScope(); }
     299                {
     300                        typedefTable.enterScope();
     301                }
    301302        ;
    302303
    303304pop:
    304                 { typedefTable.leaveScope(); }
     305                {
     306                        typedefTable.leaveScope();
     307                }
    305308        ;
    306309
     
    309312constant:
    310313                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
    311         INTEGERconstant                                                         { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
     314INTEGERconstant                                                                 { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
    312315        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    313316        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
     
    335338        ;
    336339
    337 string_literal:
    338         string_literal_list                                                     { $$ = build_constantStr( *$1 ); }
    339         ;
    340 
    341340string_literal_list:                                                                    // juxtaposed strings are concatenated
    342         STRINGliteral                                                           { $$ = $1; } // conversion from tok to str
     341        STRINGliteral                                                           { $$ = build_constantStr( *$1 ); }
    343342        | string_literal_list STRINGliteral
    344343                {
    345                         appendStr( $1, $2 );                                            // append 2nd juxtaposed string to 1st
     344                        appendStr( $1->get_constant()->get_value(), $2 );
    346345                        delete $2;                                                                      // allocated by lexer
    347                         $$ = $1;                                                                        // conversion from tok to str
     346                        $$ = $1;
    348347                }
    349348        ;
     
    372371        | postfix_expression '(' argument_expression_list ')'
    373372                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    374                 // ambiguity with .0 so space required after field-selection, e.g.
     373        // ambiguity with .0 so space required after field-selection, e.g.
    375374                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    376375        | postfix_expression '.' no_attr_identifier
     
    390389                        Token fn;
    391390                        fn.str = new std::string( "?{}" ); // location undefined
    392                         $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) );
     391                        $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_link( $3 ) ) );
    393392                }
    394393        ;
     
    397396        argument_expression
    398397        | argument_expression_list ',' argument_expression
    399                 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     398                { $$ = (ExpressionNode *)( $1->set_link( $3 )); }
    400399        ;
    401400
     
    408407field_list:                                                                                             // CFA, tuple field selector
    409408        field
    410         | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     409        | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_link( $3 ); }
    411410        ;
    412411
     
    414413        no_attr_identifier
    415414                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    416                 // ambiguity with .0 so space required after field-selection, e.g.
     415        // ambiguity with .0 so space required after field-selection, e.g.
    417416                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    418417        | no_attr_identifier '.' field
     
    432431        | constant
    433432                { $$ = $1; }
    434         | string_literal
     433        | string_literal_list
    435434                { $$ = new ExpressionNode( $1 ); }
    436435        | EXTENSION cast_expression                                                     // GCC
     
    608607assignment_operator:
    609608        '='                                                                                     { $$ = OperKinds::Assign; }
    610         | ATassign                                                                      { $$ = OperKinds::AtAssn; }
    611609        | MULTassign                                                            { $$ = OperKinds::MulAssn; }
    612610        | DIVassign                                                                     { $$ = OperKinds::DivAssn; }
     
    629627                { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    630628        | '[' push ',' tuple_expression_list pop ']'
    631                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
     629                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_link( $4 ) ) ); }
    632630        | '[' push assignment_expression ',' tuple_expression_list pop ']'
    633                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
     631                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_link( $5 ) ) ); }
    634632        ;
    635633
     
    637635        assignment_expression_opt
    638636        | tuple_expression_list ',' assignment_expression_opt
    639                 { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     637                { $$ = (ExpressionNode *)$1->set_link( $3 ); }
    640638        ;
    641639
     
    667665                        Token fn;
    668666                        fn.str = new std::string( "^?{}" ); // location undefined
    669                         $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
     667                        $$ = new StatementNode2( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_link( $4 ) ) ) ) );
    670668                }
    671669        ;
     
    681679compound_statement:
    682680        '{' '}'
    683                 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
     681                { $$ = new CompoundStmtNode( (StatementNode *)0 ); }
    684682        | '{'
    685683                // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
     
    688686          local_label_declaration_opt                                           // GCC, local labels
    689687          block_item_list pop '}'                                                       // C99, intermix declarations and statements
    690                 { $$ = new StatementNode( build_compound( $5 ) ); }
     688                { $$ = new CompoundStmtNode( $5 ); }
    691689        ;
    692690
     
    694692        block_item
    695693        | block_item_list push block_item
    696                 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
     694                { if ( $1 != 0 ) { $1->set_link( $3 ); $$ = $1; } }
    697695        ;
    698696
     
    702700        | EXTENSION declaration                                                         // GCC
    703701                {       // mark all fields in list
    704                         for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
     702                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() )
    705703                                iter->set_extension( true );
    706704                        $$ = new StatementNode( $2 );
     
    714712        statement
    715713        | statement_list statement
    716                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     714                { if ( $1 != 0 ) { $1->set_link( $2 ); $$ = $1; } }
    717715        ;
    718716
    719717expression_statement:
    720718        comma_expression_opt ';'
    721                 { $$ = new StatementNode( build_expr( $1 ) ); }
     719                { $$ = new StatementNode2( build_expr( $1 ) ); }
    722720        ;
    723721
     
    725723        IF '(' comma_expression ')' statement                           %prec THEN
    726724                // explicitly deal with the shift/reduce conflict on if/else
    727                 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
     725                { $$ = new StatementNode2( build_if( $3, $5, nullptr ) ); }
    728726        | IF '(' comma_expression ')' statement ELSE statement
    729                 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
     727                { $$ = new StatementNode2( build_if( $3, $5, $7 ) ); }
    730728        | SWITCH '(' comma_expression ')' case_clause           // CFA
    731                 { $$ = new StatementNode( build_switch( $3, $5 ) ); }
     729                { $$ = new StatementNode2( build_switch( $3, $5 ) ); }
    732730        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    733731                {
    734                         StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
     732                        StatementNode *sw = new StatementNode2( build_switch( $3, $8 ) );
    735733                        // The semantics of the declaration list is changed to include associated initialization, which is performed
    736734                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
     
    738736                        // therefore, are removed from the grammar even though C allows it. The change also applies to choose
    739737                        // statement.
    740                         $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
     738                        $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw;
    741739                }
    742740        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    743                 { $$ = new StatementNode( build_switch( $3, $5 ) ); }
     741                { $$ = new StatementNode2( build_switch( $3, $5 ) ); }
    744742        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
    745743                {
    746                         StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
    747                         $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
     744                        StatementNode *sw = new StatementNode2( build_switch( $3, $8 ) );
     745                        $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw;
    748746                }
    749747        ;
     
    760758
    761759case_value_list:                                                                                // CFA
    762         case_value                                                                      { $$ = new StatementNode( build_case( $1 ) ); }
     760        //case_value                                                                    { $$ = new StatementNode( StatementNode::Case, $1, 0 ); }
     761        case_value                                                                      { $$ = new StatementNode2( build_case( $1 ) ); }
    763762                // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
    764         | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); }
     763        | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_link( new StatementNode2( build_case( $3 ) ) ) ); }
    765764        ;
    766765
    767766case_label:                                                                                             // CFA
    768767        CASE case_value_list ':'                                        { $$ = $2; }
    769         | DEFAULT ':'                                                           { $$ = new StatementNode( build_default() ); }
     768        | DEFAULT ':'                                                           { $$ = new StatementNode2( build_default() ); }
    770769                // A semantic check is required to ensure only one default clause per switch/choose statement.
    771770        ;
     
    773772case_label_list:                                                                                // CFA
    774773        case_label
    775         | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_last( $2 )); }
     774        | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_link( $2 )); }
    776775        ;
    777776
    778777case_clause:                                                                                    // CFA
    779         case_label_list statement                                       { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
     778        case_label_list statement                                       { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
    780779        ;
    781780
     
    788787switch_clause_list:                                                                             // CFA
    789788        case_label_list statement_list
    790                 { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
     789                { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
    791790        | switch_clause_list case_label_list statement_list
    792                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }
     791                { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( $3 ) ) ) ); }
    793792        ;
    794793
     
    803802                { $$ = $1->append_last_case( $2 ); }
    804803        | case_label_list statement_list fall_through_opt
    805                 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
     804                { $$ = $1->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$2, *$3 ) ) ) ); }
    806805        | choose_clause_list case_label_list fall_through
    807                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
     806                { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); }
    808807        | choose_clause_list case_label_list statement_list fall_through_opt
    809                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
     808                { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$3, *$4 ) ) ) ) ) ); }
    810809        ;
    811810
    812811fall_through_opt:                                                                               // CFA
    813812        // empty
    814                 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break
     813                { $$ = new StatementNode2( build_branch( "", BranchStmt::Break ) ); } // insert implicit break
    815814        | fall_through
    816815        ;
     
    825824iteration_statement:
    826825        WHILE '(' comma_expression ')' statement
    827                 { $$ = new StatementNode( build_while( $3, $5 ) ); }
     826                { $$ = new StatementNode2( build_while( $3, $5 ) ); }
    828827        | DO statement WHILE '(' comma_expression ')' ';'
    829                 { $$ = new StatementNode( build_while( $5, $2 ) ); }
     828                { $$ = new StatementNode2( build_while( $5, $2 ) ); }
    830829        | FOR '(' push for_control_expression ')' statement
    831                 { $$ = new StatementNode( build_for( $4, $6 ) ); }
     830                { $$ = new StatementNode2( build_for( $4, $6 ) ); }
    832831        ;
    833832
     
    841840jump_statement:
    842841        GOTO IDENTIFIER ';'
    843                 { $$ = new StatementNode( build_branch( $2, BranchStmt::Goto ) ); }
     842                { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Goto ) ); }
    844843        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
    845844                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
    846845                // whereas normal operator precedence yields goto (*i)+3;
    847                 { $$ = new StatementNode( build_computedgoto( $3 ) ); }
     846                { $$ = new StatementNode2( build_computedgoto( $3 ) ); }
    848847        | CONTINUE ';'
    849848                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    850                 { $$ = new StatementNode( build_branch( BranchStmt::Continue ) ); }
     849                { $$ = new StatementNode2( build_branch( "", BranchStmt::Continue ) ); }
    851850        | CONTINUE IDENTIFIER ';'                                                       // CFA, multi-level continue
    852851                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    853852                // the target of the transfer appears only at the start of an iteration statement.
    854                 { $$ = new StatementNode( build_branch( $2, BranchStmt::Continue ) ); }
     853                { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Continue ) ); delete $2; }
    855854        | BREAK ';'
    856855                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    857                 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); }
     856                { $$ = new StatementNode2( build_branch( "", BranchStmt::Break ) ); }
    858857        | BREAK IDENTIFIER ';'                                                          // CFA, multi-level exit
    859858                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    860859                // the target of the transfer appears only at the start of an iteration statement.
    861                 { $$ = new StatementNode( build_branch( $2, BranchStmt::Break ) ); }
     860                { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Break ) ); delete $2; }
    862861        | RETURN comma_expression_opt ';'
    863                 { $$ = new StatementNode( build_return( $2 ) ); }
     862                { $$ = new StatementNode2( build_return( $2 ) ); }
    864863        | THROW assignment_expression_opt ';'                           // handles rethrow
    865                 { $$ = new StatementNode( build_throw( $2 ) ); }
     864                { $$ = new StatementNode2( build_throw( $2 ) ); }
    866865        | THROWRESUME assignment_expression_opt ';'                     // handles reresume
    867                 { $$ = new StatementNode( build_throw( $2 ) ); }
     866                { $$ = new StatementNode2( build_throw( $2 ) ); }
    868867        | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume
    869                 { $$ = new StatementNode( build_throw( $2 ) ); }
     868                { $$ = new StatementNode2( build_throw( $2 ) ); }
    870869        ;
    871870
    872871exception_statement:
    873872        TRY compound_statement handler_list
    874                 { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
     873                { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }
    875874        | TRY compound_statement finally_clause
    876                 { $$ = new StatementNode( build_try( $2, 0, $3 ) ); }
     875                { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }
    877876        | TRY compound_statement handler_list finally_clause
    878                 { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }
     877                {
     878                        $3->set_link( $4 );
     879                        $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 ))));
     880                }
    879881        ;
    880882
    881883handler_list:
     884                // There must be at least one catch clause
    882885        handler_clause
    883886                // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block.
    884887        | CATCH '(' ELLIPSIS ')' compound_statement
    885                 { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
     888                { $$ = StatementNode::newCatchStmt( 0, $5, true ); }
    886889        | handler_clause CATCH '(' ELLIPSIS ')' compound_statement
    887                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
     890                { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); }
    888891        | CATCHRESUME '(' ELLIPSIS ')' compound_statement
    889                 { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
     892                { $$ = StatementNode::newCatchStmt( 0, $5, true ); }
    890893        | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement
    891                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
     894                { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); }
    892895        ;
    893896
    894897handler_clause:
    895898        CATCH '(' push push exception_declaration pop ')' compound_statement pop
    896                 { $$ = new StatementNode( build_catch( $5, $8 ) ); }
     899                { $$ = StatementNode::newCatchStmt( $5, $8 ); }
    897900        | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop
    898         { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
     901                { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); }
    899902        | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    900                 { $$ = new StatementNode( build_catch( $5, $8 ) ); }
     903                { $$ = StatementNode::newCatchStmt( $5, $8 ); }
    901904        | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    902                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
     905                { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); }
    903906        ;
    904907
     
    906909        FINALLY compound_statement
    907910                {
    908                         $$ = new StatementNode( build_finally( $2 ) );
     911                        $$ = new StatementNode( StatementNode::Finally, 0, $2 );
     912                        std::cout << "Just created a finally node" << std::endl;
    909913                }
    910914        ;
     
    933937
    934938asm_statement:
    935         ASM asm_volatile_opt '(' string_literal ')' ';'
    936                 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
    937         | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
    938                 { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
    939         | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    940                 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
    941         | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    942                 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
    943         | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    944                 { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
     939        ASM asm_volatile_opt '(' string_literal_list ')' ';'
     940                { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, 0 ); }
     941        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC
     942                { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6 ); }
     943        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';'
     944                { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8 ); }
     945        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
     946                { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8, $10 ); }
     947        | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
     948                { $$ = new AsmStmtNode( StatementNode::Asm, $2, $5, 0, $8, $10, $12 ); }
    945949        ;
    946950
     
    961965        asm_operand
    962966        | asm_operands_list ',' asm_operand
    963                 { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     967                { $$ = (ExpressionNode *)$1->set_link( $3 ); }
    964968        ;
    965969
    966970asm_operand:                                                                                    // GCC
    967         string_literal '(' constant_expression ')'
    968                 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
    969         | '[' constant_expression ']' string_literal '(' constant_expression ')'
    970         { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
     971        string_literal_list '(' constant_expression ')'
     972                { $$ = new ExpressionNode( build_asm( 0, $1, $3 ) ); }
     973        | '[' constant_expression ']' string_literal_list '(' constant_expression ')'
     974        { $$ = new ExpressionNode( build_asm( $2, $4, $6 ) ); }
    971975        ;
    972976
     
    974978        // empty
    975979                { $$ = 0; }                                                                             // use default argument
    976         | string_literal
     980        | string_literal_list
    977981                { $$ = new ExpressionNode( $1 ); }
    978         | asm_clobbers_list_opt ',' string_literal
    979                 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
     982        | asm_clobbers_list_opt ',' string_literal_list
     983        { $$ = (ExpressionNode *)$1->set_link( new ExpressionNode( $3 ) ); }
    980984        ;
    981985
    982986label_list:
    983987        no_attr_identifier
    984                 {
    985                         $$ = new LabelNode(); $$->labels.push_back( *$1 );
    986                         delete $1;                                                                      // allocated by lexer
    987                 }
     988                { $$ = new LabelNode(); $$->append_label( $1 ); }
    988989        | label_list ',' no_attr_identifier
    989                 {
    990                         $$ = $1; $1->labels.push_back( *$3 );
    991                         delete $3;                                                                      // allocated by lexer
    992                 }
     990                { $$ = $1; $1->append_label( $3 ); }
    993991        ;
    994992
     
    12881286        type_qualifier_name
    12891287        | attribute
    1290                 //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }
     1288        //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }
    12911289        ;
    12921290
     
    13331331
    13341332storage_class:
     1333        storage_class_name
     1334        ;
     1335
     1336storage_class_name:
    13351337        EXTERN
    13361338                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Extern ); }
     
    13421344                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Register ); }
    13431345        | INLINE                                                                                        // C99
    1344                 //{ $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); }
    1345                 { $$ = new DeclarationNode; $$->isInline = true; }
     1346                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); }
    13461347        | FORTRAN                                                                                       // C99
    13471348                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Fortran ); }
    13481349        | NORETURN                                                                                      // C11
    1349                 //{ $$ = DeclarationNode::newStorageClass( DeclarationNode::Noreturn ); }
    1350                 { $$ = new DeclarationNode; $$->isNoreturn = true; }
     1350                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Noreturn ); }
    13511351        | THREADLOCAL                                                                           // C11
    13521352                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Threadlocal ); }
     
    15041504        | EXTENSION field_declaring_list ';'                            // GCC
    15051505                {       // mark all fields in list
    1506                         for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
     1506                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() )
    15071507                                iter->set_extension( true );
    15081508                        $$ = $2;
     
    17501750        | initializer
    17511751        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
    1752         | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
     1752        | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_link( $3 ) ); }
    17531753        | initializer_list ',' designation initializer
    1754                 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
     1754                { $$ = (InitializerNode *)( $1->set_link( $4->set_designators( $3 ) ) ); }
    17551755        ;
    17561756
     
    17741774        designator
    17751775        | designator_list designator
    1776                 { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); }
     1776                { $$ = (ExpressionNode *)( $1->set_link( $2 ) ); }
    17771777        //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
    17781778        ;
     
    18801880        | assignment_expression
    18811881        | type_name_list ',' type_name
    1882                 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
     1882                { $$ = (ExpressionNode *)( $1->set_link( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
    18831883        | type_name_list ',' assignment_expression
    1884                 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     1884                { $$ = (ExpressionNode *)( $1->set_link( $3 )); }
    18851885        ;
    18861886
     
    19811981                {}                                                                                              // empty input file
    19821982        | external_definition_list
    1983                 { parseTree = parseTree != nullptr ? parseTree->appendList( $1 ) : $1;  }
     1983                {
     1984                        if ( theTree ) {
     1985                                theTree->appendList( $1 );
     1986                        } else {
     1987                                theTree = $1;
     1988                        }
     1989                }
    19841990        ;
    19851991
     
    19871993        external_definition
    19881994        | external_definition_list push external_definition
    1989                 { $$ = $1 != nullptr ? $1->appendList( $3 ) : $3; }
     1995                { $$ = ( $1 != NULL ) ? $1->appendList( $3 ) : $3; }
    19901996        ;
    19911997
     
    20032009        | EXTERN STRINGliteral
    20042010                {
    2005                         linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
     2011                        linkageStack.push( linkage );
    20062012                        linkage = LinkageSpec::fromString( *$2 );
    20072013                }
     
    20142020        | EXTENSION external_definition
    20152021                {       // mark all fields in list
    2016                         for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
     2022                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() )
    20172023                                iter->set_extension( true );
    20182024                        $$ = $2;
     
    21152121asm_name_opt:                                                                                   // GCC
    21162122        // empty
    2117         | ASM '(' string_literal_list ')' attribute_list_opt { delete $3; }     // FIX ME: unimplemented
     2123        | ASM '(' string_literal_list ')' attribute_list_opt
    21182124        ;
    21192125
     
    21442150        // empty
    21452151        | any_word
    2146         | any_word '(' comma_expression_opt ')' { delete $3; } // FIX ME: unimplemented
     2152        | any_word '(' comma_expression_opt ')'
    21472153        ;
    21482154
    21492155any_word:                                                                                               // GCC
    2150         identifier_or_type_name { delete $1; }                          // FIX ME: unimplemented
    2151         | storage_class { delete $1; }                                          // FIX ME: unimplemented
    2152         | basic_type_name { delete $1; }                                        // FIX ME: unimplemented
    2153         | type_qualifier { delete $1; }                                         // FIX ME: unimplemented
     2156        identifier_or_type_name {}
     2157        | storage_class_name {}
     2158        | basic_type_name {}
     2159        | type_qualifier {}
    21542160        ;
    21552161
     
    28492855// ----end of grammar----
    28502856
    2851 extern char *yytext;
    2852 
    28532857void yyerror( const char * ) {
    28542858        std::cout << "Error ";
Note: See TracChangeset for help on using the changeset viewer.