Ignore:
Timestamp:
Aug 16, 2016, 3:20:06 PM (9 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1f6d4624
Parents:
950f7a7 (diff), 7880579 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r950f7a7 r7527e63  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 12 20:52:53 2016
    13 // Update Count     : 1661
     12// Last Modified On : Mon Aug 15 15:18:19 2016
     13// Update Count     : 1891
    1414//
    1515
     
    6060std::stack< LinkageSpec::Type > linkageStack;
    6161TypedefTable typedefTable;
     62
     63void appendStr( std::string &to, std::string *from ) {
     64        // "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 ) );
     66} // appendStr
    6267%}
    6368
     
    116121        DeclarationNode::TypeClass tclass;
    117122        StatementNode *sn;
    118         ConstantNode *constant;
     123        ConstantExpr *constant;
     124        ForCtl *fctl;
    119125        LabelNode *label;
    120126        InitializerNode *in;
     127        OperKinds op;
    121128        bool flag;
    122129}
     
    127134
    128135// expressions
    129 %type<constant> constant
     136%type<en> constant
    130137%type<en> tuple                                                 tuple_expression_list
    131 %type<en> ptrref_operator                               unary_operator                          assignment_operator
     138%type<op> ptrref_operator                               unary_operator                          assignment_operator
    132139%type<en> primary_expression                    postfix_expression                      unary_expression
    133140%type<en> cast_expression                               multiplicative_expression       additive_expression                     shift_expression
     
    136143%type<en> constant_expression                   assignment_expression           assignment_expression_opt
    137144%type<en> comma_expression                              comma_expression_opt
    138 %type<en> argument_expression_list              argument_expression                     for_control_expression          assignment_opt
     145%type<en> argument_expression_list              argument_expression                     assignment_opt
     146%type<fctl> for_control_expression
    139147%type<en> subrange
    140148%type<en> asm_operands_opt asm_operands_list asm_operand
    141149%type<label> label_list
    142 %type<constant> asm_clobbers_list_opt
     150%type<en> asm_clobbers_list_opt
    143151%type<flag> asm_volatile_opt
    144152
     
    150158%type<sn> block_item_list                               block_item
    151159%type<sn> case_clause
    152 %type<en> case_value                                    case_value_list
    153 %type<sn> case_label                                    case_label_list
     160%type<en> case_value
     161%type<sn> case_value_list                               case_label                                      case_label_list
    154162%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    155 %type<pn> handler_list                                  handler_clause                          finally_clause
     163%type<sn> handler_list                                  handler_clause                          finally_clause
    156164
    157165// declarations
     
    303311constant:
    304312                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
    305 INTEGERconstant                                                                 { $$ = makeConstant( ConstantNode::Integer, $1 ); }
    306         | FLOATINGconstant                                                      { $$ = makeConstant( ConstantNode::Float, $1 ); }
    307         | CHARACTERconstant                                                     { $$ = makeConstant( ConstantNode::Character, $1 ); }
     313INTEGERconstant                                                                 { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
     314        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
     315        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
    308316        ;
    309317
     
    330338
    331339string_literal_list:                                                                    // juxtaposed strings are concatenated
    332         STRINGliteral                                                           { $$ = makeConstantStr( ConstantNode::String, $1 ); }
    333         | string_literal_list STRINGliteral                     { $$ = $1->appendstr( $2 ); }
     340        STRINGliteral                                                           { $$ = build_constantStr( *$1 ); }
     341        | string_literal_list STRINGliteral
     342                {
     343                        appendStr( $1->get_constant()->get_value(), $2 );
     344                        delete $2;                                                                      // allocated by lexer
     345                        $$ = $1;
     346                }
    334347        ;
    335348
     
    338351primary_expression:
    339352        IDENTIFIER                                                                                      // typedef name cannot be used as a variable name
    340                 { $$ = new VarRefNode( $1 ); }
     353                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    341354        | zero_one
    342                 { $$ = new VarRefNode( $1 ); }
     355                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    343356        | '(' comma_expression ')'
    344357                { $$ = $2; }
    345358        | '(' compound_statement ')'                                            // GCC, lambda expression
    346                 { $$ = new ValofExprNode( $2 ); }
     359        { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
    347360        ;
    348361
     
    354367                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
    355368                // equivalent to the old x[i,j].
    356                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Index ), $1, $4 ); }
     369                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
    357370        | postfix_expression '(' argument_expression_list ')'
    358                 { $$ = new CompositeExprNode( $1, $3 ); }
     371                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    359372        // ambiguity with .0 so space required after field-selection, e.g.
    360373                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    361374        | postfix_expression '.' no_attr_identifier
    362                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), $1, new VarRefNode( $3 )); }
     375                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
    363376        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
    364377        | postfix_expression ARROW no_attr_identifier
    365                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), $1, new VarRefNode( $3 )); }
     378                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
    366379        | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
    367380        | postfix_expression ICR
    368                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::IncrPost ), $1 ); }
     381                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
    369382        | postfix_expression DECR
    370                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::DecrPost ), $1 ); }
     383                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
    371384        | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99
    372                 { $$ = new CompoundLiteralNode( $2, new InitializerNode( $5, true ) ); }
     385                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
    373386        | postfix_expression '{' argument_expression_list '}' // CFA
    374387                {
    375                         Token fn; fn.str = new std::string( "?{}" ); // location undefined
    376                         $$ = new CompositeExprNode( new VarRefNode( fn ), (ExpressionNode *)( $1 )->set_link( $3 ) );
     388                        Token fn;
     389                        fn.str = new std::string( "?{}" ); // location undefined
     390                        $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) );
    377391                }
    378392        ;
     
    381395        argument_expression
    382396        | argument_expression_list ',' argument_expression
    383                 { $$ = (ExpressionNode *)( $1->set_link( $3 )); }
     397                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    384398        ;
    385399
     
    388402                { $$ = 0; }                                                                             // use default argument
    389403        | assignment_expression
    390         | no_attr_identifier ':' assignment_expression
    391                 { $$ = $3->set_argName( $1 ); }
    392                 // Only a list of no_attr_identifier_or_type_name is allowed in this context. However, there is insufficient
    393                 // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used
    394                 // with an appropriate semantic check.
    395         | '[' push assignment_expression pop ']' ':' assignment_expression
    396                 { $$ = $7->set_argName( $3 ); }
    397         | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression
    398                 { $$ = $9->set_argName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); }
    399404        ;
    400405
    401406field_list:                                                                                             // CFA, tuple field selector
    402407        field
    403         | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_link( $3 ); }
     408        | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    404409        ;
    405410
    406411field:                                                                                                  // CFA, tuple field selector
    407412        no_attr_identifier
    408                 { $$ = new VarRefNode( $1 ); }
     413                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    409414        // ambiguity with .0 so space required after field-selection, e.g.
    410415                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    411416        | no_attr_identifier '.' field
    412                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $3 ); }
     417                { $$ = new ExpressionNode( build_fieldSel( $3, build_varref( $1 ) ) ); }
    413418        | no_attr_identifier '.' '[' push field_list pop ']'
    414                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $5 ); }
     419                { $$ = new ExpressionNode( build_fieldSel( $5, build_varref( $1 ) ) ); }
    415420        | no_attr_identifier ARROW field
    416                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $3 ); }
     421                { $$ = new ExpressionNode( build_pfieldSel( $3, build_varref( $1 ) ) ); }
    417422        | no_attr_identifier ARROW '[' push field_list pop ']'
    418                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $5 ); }
     423                { $$ = new ExpressionNode( build_pfieldSel( $5, build_varref( $1 ) ) ); }
    419424        ;
    420425
     
    426431                { $$ = $1; }
    427432        | string_literal_list
    428                 { $$ = $1; }
     433                { $$ = new ExpressionNode( $1 ); }
    429434        | EXTENSION cast_expression                                                     // GCC
    430435                { $$ = $2->set_extension( true ); }
    431         | ptrref_operator cast_expression                                       // CFA
    432                 { $$ = new CompositeExprNode( $1, $2 ); }
    433436                // '*' ('&') is separated from unary_operator because of shift/reduce conflict in:
    434437                //              { * X; }         // dereference X
    435438                //              { * int X; } // CFA declaration of pointer to int
     439        | ptrref_operator cast_expression                                       // CFA
     440                {
     441                        switch ( $1 ) {
     442                          case OperKinds::AddressOf:
     443                                $$ = new ExpressionNode( build_addressOf( $2 ) );
     444                                break;
     445                          case OperKinds::PointTo:
     446                                $$ = new ExpressionNode( build_unary_val( $1, $2 ) );
     447                                break;
     448                          default:
     449                                assert( false );
     450                        }
     451                }
    436452        | unary_operator cast_expression
    437                 { $$ = new CompositeExprNode( $1, $2 ); }
     453                { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }
    438454        | ICR unary_expression
    439                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); }
     455                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Incr, $2 ) ); }
    440456        | DECR unary_expression
    441                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Decr ), $2 ); }
     457                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); }
    442458        | SIZEOF unary_expression
    443                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), $2 ); }
     459                { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); }
    444460        | SIZEOF '(' type_name_no_function ')'
    445                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), new TypeValueNode( $3 )); }
     461                { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); }
     462        | ALIGNOF unary_expression                                                      // GCC, variable alignment
     463                { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
     464        | ALIGNOF '(' type_name_no_function ')'                         // GCC, type alignment
     465                { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
    446466        | OFFSETOF '(' type_name_no_function ',' no_attr_identifier ')'
    447                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::OffsetOf ), new TypeValueNode( $3 ), new VarRefNode( $5 )); }
     467                { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); }
    448468        | ATTR_IDENTIFIER
    449                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 )); }
     469                { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), nullptr ) ); }
     470        | ATTR_IDENTIFIER '(' argument_expression ')'
     471                { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); }
    450472        | ATTR_IDENTIFIER '(' type_name ')'
    451                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), new TypeValueNode( $3 )); }
    452         | ATTR_IDENTIFIER '(' argument_expression ')'
    453                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), $3 ); }
    454         | ALIGNOF unary_expression                                                      // GCC, variable alignment
    455                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), $2 ); }
    456         | ALIGNOF '(' type_name_no_function ')'                         // GCC, type alignment
    457                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3 ) ); }
     473                { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); }
    458474//      | ANDAND IDENTIFIER                                                                     // GCC, address of label
    459 //              { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true ) ); }
     475//              { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2, true ) ); }
    460476        ;
    461477
    462478ptrref_operator:
    463         '*'                                                                                     { $$ = new OperatorNode( OperatorNode::PointTo ); }
    464         | '&'                                                                           { $$ = new OperatorNode( OperatorNode::AddressOf ); }
     479        '*'                                                                                     { $$ = OperKinds::PointTo; }
     480        | '&'                                                                           { $$ = OperKinds::AddressOf; }
    465481                // GCC, address of label must be handled by semantic check for ref,ref,label
    466         | ANDAND                                                                        { $$ = new OperatorNode( OperatorNode::And ); }
     482//      | ANDAND                                                                        { $$ = OperKinds::And; }
    467483        ;
    468484
    469485unary_operator:
    470         '+'                                                                                     { $$ = new OperatorNode( OperatorNode::UnPlus ); }
    471         | '-'                                                                           { $$ = new OperatorNode( OperatorNode::UnMinus ); }
    472         | '!'                                                                           { $$ = new OperatorNode( OperatorNode::Neg ); }
    473         | '~'                                                                           { $$ = new OperatorNode( OperatorNode::BitNeg ); }
     486        '+'                                                                                     { $$ = OperKinds::UnPlus; }
     487        | '-'                                                                           { $$ = OperKinds::UnMinus; }
     488        | '!'                                                                           { $$ = OperKinds::Neg; }
     489        | '~'                                                                           { $$ = OperKinds::BitNeg; }
    474490        ;
    475491
     
    477493        unary_expression
    478494        | '(' type_name_no_function ')' cast_expression
    479                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4 ); }
     495                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    480496        | '(' type_name_no_function ')' tuple
    481                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4 ); }
     497                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    482498        ;
    483499
     
    485501        cast_expression
    486502        | multiplicative_expression '*' cast_expression
    487                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mul ), $1, $3 ); }
     503                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); }
    488504        | multiplicative_expression '/' cast_expression
    489                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Div ), $1, $3 ); }
     505                { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); }
    490506        | multiplicative_expression '%' cast_expression
    491                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mod ), $1, $3 ); }
     507                { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); }
    492508        ;
    493509
     
    495511        multiplicative_expression
    496512        | additive_expression '+' multiplicative_expression
    497                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Plus ), $1, $3 ); }
     513                { $$ = new ExpressionNode( build_binary_val( OperKinds::Plus, $1, $3 ) ); }
    498514        | additive_expression '-' multiplicative_expression
    499                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Minus ), $1, $3 ); }
     515                { $$ = new ExpressionNode( build_binary_val( OperKinds::Minus, $1, $3 ) ); }
    500516        ;
    501517
     
    503519        additive_expression
    504520        | shift_expression LS additive_expression
    505                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LShift ), $1, $3 ); }
     521                { $$ = new ExpressionNode( build_binary_val( OperKinds::LShift, $1, $3 ) ); }
    506522        | shift_expression RS additive_expression
    507                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::RShift ), $1, $3 ); }
     523                { $$ = new ExpressionNode( build_binary_val( OperKinds::RShift, $1, $3 ) ); }
    508524        ;
    509525
     
    511527        shift_expression
    512528        | relational_expression '<' shift_expression
    513                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LThan ), $1, $3 ); }
     529                { $$ = new ExpressionNode( build_binary_val( OperKinds::LThan, $1, $3 ) ); }
    514530        | relational_expression '>' shift_expression
    515                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GThan ), $1, $3 ); }
     531                { $$ = new ExpressionNode( build_binary_val( OperKinds::GThan, $1, $3 ) ); }
    516532        | relational_expression LE shift_expression
    517                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LEThan ), $1, $3 ); }
     533                { $$ = new ExpressionNode( build_binary_val( OperKinds::LEThan, $1, $3 ) ); }
    518534        | relational_expression GE shift_expression
    519                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GEThan ), $1, $3 ); }
     535                { $$ = new ExpressionNode( build_binary_val( OperKinds::GEThan, $1, $3 ) ); }
    520536        ;
    521537
     
    523539        relational_expression
    524540        | equality_expression EQ relational_expression
    525                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Eq ), $1, $3 ); }
     541                { $$ = new ExpressionNode( build_binary_val( OperKinds::Eq, $1, $3 ) ); }
    526542        | equality_expression NE relational_expression
    527                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neq ), $1, $3 ); }
     543                { $$ = new ExpressionNode( build_binary_val( OperKinds::Neq, $1, $3 ) ); }
    528544        ;
    529545
     
    531547        equality_expression
    532548        | AND_expression '&' equality_expression
    533                 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::BitAnd ), $1, $3 ); }
     549                { $$ = new ExpressionNode( build_binary_val( OperKinds::BitAnd, $1, $3 ) ); }
    534550        ;
    535551
     
    537553        AND_expression
    538554        | exclusive_OR_expression '^' AND_expression
    539                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Xor ), $1, $3 ); }
     555                { $$ = new ExpressionNode( build_binary_val( OperKinds::Xor, $1, $3 ) ); }
    540556        ;
    541557
     
    543559        exclusive_OR_expression
    544560        | inclusive_OR_expression '|' exclusive_OR_expression
    545                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::BitOr ), $1, $3 ); }
     561                { $$ = new ExpressionNode( build_binary_val( OperKinds::BitOr, $1, $3 ) ); }
    546562        ;
    547563
     
    549565        inclusive_OR_expression
    550566        | logical_AND_expression ANDAND inclusive_OR_expression
    551                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::And ), $1, $3 ); }
     567                { $$ = new ExpressionNode( build_and_or( $1, $3, true ) ); }
    552568        ;
    553569
     
    555571        logical_AND_expression
    556572        | logical_OR_expression OROR logical_AND_expression
    557                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Or ), $1, $3 ); }
     573                { $$ = new ExpressionNode( build_and_or( $1, $3, false ) ); }
    558574        ;
    559575
     
    561577        logical_OR_expression
    562578        | logical_OR_expression '?' comma_expression ':' conditional_expression
    563                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 ) ) ); }
     579                { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
     580                // FIX ME: this hack computes $1 twice
    564581        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    565                 { $$=new CompositeExprNode( new OperatorNode( OperatorNode::NCond ), $1, $4 ); }
     582                { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }
    566583        | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression
    567                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 ) ) ); }
     584                { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
    568585        ;
    569586
     
    575592                // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples
    576593        conditional_expression
    577         | unary_expression '=' assignment_expression
    578                 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $3 ); }
    579594        | unary_expression assignment_operator assignment_expression
    580                 { $$ =new CompositeExprNode( $2, $1, $3 ); }
     595                { $$ = new ExpressionNode( build_binary_ptr( $2, $1, $3 ) ); }
    581596        | tuple assignment_opt                                                          // CFA, tuple expression
    582                 { $$ = ( $2 == 0 ) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2 ); }
     597                { $$ = ( $2 == 0 ) ? $1 : new ExpressionNode( build_binary_ptr( OperKinds::Assign, $1, $2 ) ); }
    583598        ;
    584599
    585600assignment_expression_opt:
    586601        // empty
    587                 { $$ = new NullExprNode; }
     602                { $$ = nullptr; }
    588603        | assignment_expression
     604        ;
     605
     606assignment_operator:
     607        '='                                                                                     { $$ = OperKinds::Assign; }
     608        | MULTassign                                                            { $$ = OperKinds::MulAssn; }
     609        | DIVassign                                                                     { $$ = OperKinds::DivAssn; }
     610        | MODassign                                                                     { $$ = OperKinds::ModAssn; }
     611        | PLUSassign                                                            { $$ = OperKinds::PlusAssn; }
     612        | MINUSassign                                                           { $$ = OperKinds::MinusAssn; }
     613        | LSassign                                                                      { $$ = OperKinds::LSAssn; }
     614        | RSassign                                                                      { $$ = OperKinds::RSAssn; }
     615        | ANDassign                                                                     { $$ = OperKinds::AndAssn; }
     616        | ERassign                                                                      { $$ = OperKinds::ERAssn; }
     617        | ORassign                                                                      { $$ = OperKinds::OrAssn; }
    589618        ;
    590619
     
    593622                // comma_expression in new_identifier_parameter_array and new_abstract_array
    594623        '[' ']'
    595                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ) ); }
     624                { $$ = new ExpressionNode( build_tuple() ); }
    596625        | '[' push assignment_expression pop ']'
    597                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), $3 ); }
     626                { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    598627        | '[' push ',' tuple_expression_list pop ']'
    599                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(new NullExprNode)->set_link( $4 ) ); }
     628                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
    600629        | '[' push assignment_expression ',' tuple_expression_list pop ']'
    601                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 ) ) ); }
     630                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
    602631        ;
    603632
     
    605634        assignment_expression_opt
    606635        | tuple_expression_list ',' assignment_expression_opt
    607                 { $$ = (ExpressionNode *)$1->set_link( $3 ); }
    608         ;
    609 
    610 assignment_operator:
    611         MULTassign                                                                      { $$ = new OperatorNode( OperatorNode::MulAssn ); }
    612         | DIVassign                                                                     { $$ = new OperatorNode( OperatorNode::DivAssn ); }
    613         | MODassign                                                                     { $$ = new OperatorNode( OperatorNode::ModAssn ); }
    614         | PLUSassign                                                            { $$ = new OperatorNode( OperatorNode::PlusAssn ); }
    615         | MINUSassign                                                           { $$ = new OperatorNode( OperatorNode::MinusAssn ); }
    616         | LSassign                                                                      { $$ = new OperatorNode( OperatorNode::LSAssn ); }
    617         | RSassign                                                                      { $$ = new OperatorNode( OperatorNode::RSAssn ); }
    618         | ANDassign                                                                     { $$ = new OperatorNode( OperatorNode::AndAssn ); }
    619         | ERassign                                                                      { $$ = new OperatorNode( OperatorNode::ERAssn ); }
    620         | ORassign                                                                      { $$ = new OperatorNode( OperatorNode::OrAssn ); }
     636                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    621637        ;
    622638
    623639comma_expression:
    624640        assignment_expression
    625         | comma_expression ',' assignment_expression    // { $$ = (ExpressionNode *)$1->add_to_list( $3 ); }
    626                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Comma ), $1, $3 ); }
     641        | comma_expression ',' assignment_expression
     642                { $$ = new ExpressionNode( build_comma( $1, $3 ) ); }
    627643        ;
    628644
     
    646662        | '^' postfix_expression '{' argument_expression_list '}' ';' // CFA
    647663                {
    648                         Token fn; fn.str = new std::string( "^?{}" ); // location undefined
    649                         $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode( new VarRefNode( fn ),
    650                                 (ExpressionNode *)( $2 )->set_link( $4 ) ), 0 );
     664                        Token fn;
     665                        fn.str = new std::string( "^?{}" ); // location undefined
     666                        $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
    651667                }
    652668        ;
     
    662678compound_statement:
    663679        '{' '}'
    664                 { $$ = new CompoundStmtNode( (StatementNode *)0 ); }
     680                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    665681        | '{'
    666682                // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
     
    669685          local_label_declaration_opt                                           // GCC, local labels
    670686          block_item_list pop '}'                                                       // C99, intermix declarations and statements
    671                 { $$ = new CompoundStmtNode( $5 ); }
     687                { $$ = new StatementNode( build_compound( $5 ) ); }
    672688        ;
    673689
     
    675691        block_item
    676692        | block_item_list push block_item
    677                 { if ( $1 != 0 ) { $1->set_link( $3 ); $$ = $1; } }
     693                { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
    678694        ;
    679695
     
    683699        | EXTENSION declaration                                                         // GCC
    684700                {       // mark all fields in list
    685                         for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() )
     701                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
    686702                                iter->set_extension( true );
    687703                        $$ = new StatementNode( $2 );
     
    695711        statement
    696712        | statement_list statement
    697                 { if ( $1 != 0 ) { $1->set_link( $2 ); $$ = $1; } }
     713                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    698714        ;
    699715
    700716expression_statement:
    701717        comma_expression_opt ';'
    702                 { $$ = new StatementNode( StatementNode::Exp, $1, 0 ); }
     718                { $$ = new StatementNode( build_expr( $1 ) ); }
    703719        ;
    704720
     
    706722        IF '(' comma_expression ')' statement                           %prec THEN
    707723                // explicitly deal with the shift/reduce conflict on if/else
    708                 { $$ = new StatementNode( StatementNode::If, $3, $5 ); }
     724                { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    709725        | IF '(' comma_expression ')' statement ELSE statement
    710                 { $$ = new StatementNode( StatementNode::If, $3, (StatementNode *)mkList((*$5, *$7 )) ); }
     726                { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    711727        | SWITCH '(' comma_expression ')' case_clause           // CFA
    712                 { $$ = new StatementNode( StatementNode::Switch, $3, $5 ); }
     728                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    713729        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    714730                {
    715                         StatementNode *sw = new StatementNode( StatementNode::Switch, $3, $8 );
     731                        StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
    716732                        // The semantics of the declaration list is changed to include associated initialization, which is performed
    717733                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
    718734                        // statement around the switch.  Statements after the initial declaration list can never be executed, and
    719                         // therefore, are removed from the grammar even though C allows it. Change also applies to choose statement.
    720                         $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw;
     735                        // therefore, are removed from the grammar even though C allows it. The change also applies to choose
     736                        // statement.
     737                        $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    721738                }
    722739        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    723                 { $$ = new StatementNode( StatementNode::Switch, $3, $5 ); }
     740                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    724741        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
    725742                {
    726                         StatementNode *sw = new StatementNode( StatementNode::Switch, $3, $8 );
    727                         $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw;
     743                        StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
     744                        $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    728745                }
    729746        ;
     
    735752        constant_expression                                                     { $$ = $1; }
    736753        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
    737                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3 ); }
     754                { $$ = new ExpressionNode( build_range( $1, $3 ) ); }
    738755        | subrange                                                                                      // CFA, subrange
    739756        ;
    740757
    741758case_value_list:                                                                                // CFA
    742         case_value
    743         | case_value_list ',' case_value
    744                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(tupleContents( $1 ))->set_link( $3 ) ); }
     759        case_value                                                                      { $$ = new StatementNode( build_case( $1 ) ); }
     760                // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
     761        | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); }
    745762        ;
    746763
    747764case_label:                                                                                             // CFA
    748         CASE case_value_list ':'                                        { $$ = new StatementNode( StatementNode::Case, $2, 0 ); }
    749         | DEFAULT ':'                                                           { $$ = new StatementNode( StatementNode::Default ); }
     765        CASE case_value_list ':'                                        { $$ = $2; }
     766        | DEFAULT ':'                                                           { $$ = new StatementNode( build_default() ); }
    750767                // A semantic check is required to ensure only one default clause per switch/choose statement.
    751768        ;
     
    753770case_label_list:                                                                                // CFA
    754771        case_label
    755         | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_link( $2 )); }
     772        | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_last( $2 )); }
    756773        ;
    757774
    758775case_clause:                                                                                    // CFA
    759         case_label_list statement                                       { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
     776        case_label_list statement                                       { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
    760777        ;
    761778
     
    768785switch_clause_list:                                                                             // CFA
    769786        case_label_list statement_list
    770                 { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
     787                { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
    771788        | switch_clause_list case_label_list statement_list
    772                 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( $3 ) ) ) ); }
     789                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }
    773790        ;
    774791
     
    783800                { $$ = $1->append_last_case( $2 ); }
    784801        | case_label_list statement_list fall_through_opt
    785                 { $$ = $1->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$2, *$3 ) ) ) ); }
     802                { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
    786803        | choose_clause_list case_label_list fall_through
    787                 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); }
     804                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
    788805        | choose_clause_list case_label_list statement_list fall_through_opt
    789                 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$3, *$4 ) ) ) ) ) ); }
     806                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
    790807        ;
    791808
    792809fall_through_opt:                                                                               // CFA
    793810        // empty
    794                 { $$ = new StatementNode( StatementNode::Break ); }     // insert implicit break
     811                { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } // insert implicit break
    795812        | fall_through
    796813        ;
     
    805822iteration_statement:
    806823        WHILE '(' comma_expression ')' statement
    807                 { $$ = new StatementNode( StatementNode::While, $3, $5 ); }
     824                { $$ = new StatementNode( build_while( $3, $5 ) ); }
    808825        | DO statement WHILE '(' comma_expression ')' ';'
    809                 { $$ = new StatementNode( StatementNode::Do, $5, $2 ); }
     826                { $$ = new StatementNode( build_while( $5, $2 ) ); }
    810827        | FOR '(' push for_control_expression ')' statement
    811                 { $$ = new StatementNode( StatementNode::For, $4, $6 ); }
     828                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    812829        ;
    813830
    814831for_control_expression:
    815832        comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
    816                 { $$ = new ForCtlExprNode( $1, $4, $6 ); }
     833                { $$ = new ForCtl( $1, $4, $6 ); }
    817834        | declaration comma_expression_opt ';' comma_expression_opt // C99
    818                 { $$ = new ForCtlExprNode( $1, $2, $4 ); }
    819         ;
     835                { $$ = new ForCtl( $1, $2, $4 ); }
     836        ;
    820837
    821838jump_statement:
    822839        GOTO IDENTIFIER ';'
    823                 { $$ = new StatementNode( StatementNode::Goto, $2 ); }
     840                { $$ = new StatementNode( build_branch( *$2, BranchStmt::Goto ) ); }
    824841        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
    825842                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
    826843                // whereas normal operator precedence yields goto (*i)+3;
    827                 { $$ = new StatementNode( StatementNode::Goto, $3 ); }
     844                { $$ = new StatementNode( build_computedgoto( $3 ) ); }
    828845        | CONTINUE ';'
    829846                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    830                 { $$ = new StatementNode( StatementNode::Continue ); }
     847                { $$ = new StatementNode( build_branch( "", BranchStmt::Continue ) ); }
    831848        | CONTINUE IDENTIFIER ';'                                                       // CFA, multi-level continue
    832849                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    833850                // the target of the transfer appears only at the start of an iteration statement.
    834                 { $$ = new StatementNode( StatementNode::Continue, $2 ); }
     851                { $$ = new StatementNode( build_branch( *$2, BranchStmt::Continue ) ); delete $2; }
    835852        | BREAK ';'
    836853                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    837                 { $$ = new StatementNode( StatementNode::Break ); }
     854                { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); }
    838855        | BREAK IDENTIFIER ';'                                                          // CFA, multi-level exit
    839856                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    840857                // the target of the transfer appears only at the start of an iteration statement.
    841                 { $$ = new StatementNode( StatementNode::Break, $2 ); }
     858                { $$ = new StatementNode( build_branch( *$2, BranchStmt::Break ) ); delete $2; }
    842859        | RETURN comma_expression_opt ';'
    843                 { $$ = new StatementNode( StatementNode::Return, $2, 0 ); }
    844         | THROW assignment_expression_opt ';'
    845                 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); }
    846 //      | THROW ';'
    847 //              { $$ = new StatementNode( StatementNode::Throw ); }
    848         | THROWRESUME assignment_expression_opt ';'
    849                 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); }
    850         | THROWRESUME assignment_expression_opt AT assignment_expression ';'
    851                 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); }
    852 //      | THROWRESUME ';'
    853 //              { $$ = new StatementNode( StatementNode::Throw ); }
     860                { $$ = new StatementNode( build_return( $2 ) ); }
     861        | THROW assignment_expression_opt ';'                           // handles rethrow
     862                { $$ = new StatementNode( build_throw( $2 ) ); }
     863        | THROWRESUME assignment_expression_opt ';'                     // handles reresume
     864                { $$ = new StatementNode( build_throw( $2 ) ); }
     865        | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume
     866                { $$ = new StatementNode( build_throw( $2 ) ); }
    854867        ;
    855868
    856869exception_statement:
    857870        TRY compound_statement handler_list
    858                 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }
     871                { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
    859872        | TRY compound_statement finally_clause
    860                 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }
     873                { $$ = new StatementNode( build_try( $2, 0, $3 ) ); }
    861874        | TRY compound_statement handler_list finally_clause
    862                 {
    863                         $3->set_link( $4 );
    864                         $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 ))));
    865                 }
     875                { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }
    866876        ;
    867877
    868878handler_list:
    869                 // There must be at least one catch clause
    870879        handler_clause
    871880                // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block.
    872881        | CATCH '(' ELLIPSIS ')' compound_statement
    873                 { $$ = StatementNode::newCatchStmt( 0, $5, true ); }
     882                { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
    874883        | handler_clause CATCH '(' ELLIPSIS ')' compound_statement
    875                 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); }
     884                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
    876885        | CATCHRESUME '(' ELLIPSIS ')' compound_statement
    877                 { $$ = StatementNode::newCatchStmt( 0, $5, true ); }
     886                { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
    878887        | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement
    879                 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); }
     888                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
    880889        ;
    881890
    882891handler_clause:
    883892        CATCH '(' push push exception_declaration pop ')' compound_statement pop
    884                 { $$ = StatementNode::newCatchStmt( $5, $8 ); }
     893                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
    885894        | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop
    886                 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); }
     895        { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
    887896        | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    888                 { $$ = StatementNode::newCatchStmt( $5, $8 ); }
     897                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
    889898        | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    890                 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); }
     899                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
    891900        ;
    892901
     
    894903        FINALLY compound_statement
    895904                {
    896                         $$ = new StatementNode( StatementNode::Finally, 0, $2 );
    897                         std::cout << "Just created a finally node" << std::endl;
     905                        $$ = new StatementNode( build_finally( $2 ) );
    898906                }
    899907        ;
     
    923931asm_statement:
    924932        ASM asm_volatile_opt '(' string_literal_list ')' ';'
    925                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, 0 ); }
     933                { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
    926934        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC
    927                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6 ); }
     935                { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
    928936        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    929                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8 ); }
     937                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
    930938        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    931                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8, $10 ); }
     939                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
    932940        | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    933         { $$ = new AsmStmtNode( StatementNode::Asm, $2, $5, 0, $8, $10, $12 ); }
     941                { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
    934942        ;
    935943
     
    950958        asm_operand
    951959        | asm_operands_list ',' asm_operand
    952                 { $$ = (ExpressionNode *)$1->set_link( $3 ); }
     960                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    953961        ;
    954962
    955963asm_operand:                                                                                    // GCC
    956964        string_literal_list '(' constant_expression ')'
    957                 { $$ = new AsmExprNode( 0, $1, $3 ); }
     965                { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
    958966        | '[' constant_expression ']' string_literal_list '(' constant_expression ')'
    959                 { $$ = new AsmExprNode( $2, $4, $6 ); }
     967        { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
    960968        ;
    961969
     
    964972                { $$ = 0; }                                                                             // use default argument
    965973        | string_literal_list
    966                 { $$ = $1; }
     974                { $$ = new ExpressionNode( $1 ); }
    967975        | asm_clobbers_list_opt ',' string_literal_list
    968                 { $$ = (ConstantNode *)$1->set_link( $3 ); }
     976                { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
    969977        ;
    970978
    971979label_list:
    972980        no_attr_identifier
    973                 { $$ = new LabelNode(); $$->append_label( $1 ); }
     981                { $$ = new LabelNode(); $$->labels.push_back( *$1 ); }
    974982        | label_list ',' no_attr_identifier
    975                 { $$ = $1; $1->append_label( $3 ); }
     983                { $$ = $1; $1->labels.push_back( *$3 ); }
    976984        ;
    977985
     
    14891497        | EXTENSION field_declaring_list ';'                            // GCC
    14901498                {       // mark all fields in list
    1491                         for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() )
     1499                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
    14921500                                iter->set_extension( true );
    14931501                        $$ = $2;
     
    17351743        | initializer
    17361744        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
    1737         | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_link( $3 ) ); }
     1745        | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    17381746        | initializer_list ',' designation initializer
    1739                 { $$ = (InitializerNode *)( $1->set_link( $4->set_designators( $3 ) ) ); }
     1747                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
    17401748        ;
    17411749
     
    17531761        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
    17541762        | no_attr_identifier_or_type_name ':'                           // GCC, field name
    1755                 { $$ = new VarRefNode( $1 ); }
     1763                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    17561764        ;
    17571765
     
    17591767        designator
    17601768        | designator_list designator
    1761                 { $$ = (ExpressionNode *)( $1->set_link( $2 )); }
    1762         //| designator_list designator                                          { $$ = new CompositeExprNode( $1, $2 ); }
     1769                { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); }
     1770        //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
    17631771        ;
    17641772
    17651773designator:
    1766                 // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0 only ".0" and ".1"
    1767                 // allowed => semantic check
    1768         FLOATINGconstant
    1769                 { $$ = new DesignatorNode( new VarRefNode( $1 ) ); }
    1770         | '.' no_attr_identifier_or_type_name                           // C99, field name
    1771                 { $$ = new DesignatorNode( new VarRefNode( $2 ) ); }
     1774        '.' no_attr_identifier_or_type_name                                     // C99, field name
     1775                { $$ = new ExpressionNode( build_varref( $2 ) ); }
    17721776        | '[' push assignment_expression pop ']'                        // C99, single array element
    17731777                // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple.
    1774                 { $$ = new DesignatorNode( $3, true ); }
     1778                { $$ = $3; }
    17751779        | '[' push subrange pop ']'                                                     // CFA, multiple array elements
    1776                 { $$ = new DesignatorNode( $3, true ); }
     1780                { $$ = $3; }
    17771781        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    1778                 { $$ = new DesignatorNode( new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ), true ); }
     1782                { $$ = new ExpressionNode( build_range( $3, $5 ) ); }
    17791783        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
    1780                 { $$ = new DesignatorNode( $4 ); }
     1784                { $$ = $4; }
    17811785        ;
    17821786
     
    18661870type_name_list:                                                                                 // CFA
    18671871        type_name
    1868                 { $$ = new TypeValueNode( $1 ); }
     1872                { $$ = new ExpressionNode( build_typevalue( $1 ) ); }
    18691873        | assignment_expression
    18701874        | type_name_list ',' type_name
    1871                 { $$ = (ExpressionNode *)( $1->set_link( new TypeValueNode( $3 ))); }
     1875                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
    18721876        | type_name_list ',' assignment_expression
    1873                 { $$ = (ExpressionNode *)( $1->set_link( $3 )); }
     1877                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    18741878        ;
    18751879
     
    20092013        | EXTENSION external_definition
    20102014                {       // mark all fields in list
    2011                         for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() )
     2015                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
    20122016                                iter->set_extension( true );
    20132017                        $$ = $2;
     
    21052109subrange:
    21062110        constant_expression '~' constant_expression                     // CFA, integer subrange
    2107                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3 ); }
     2111                { $$ = new ExpressionNode( build_range( $1, $3 ) ); }
    21082112        ;
    21092113
Note: See TracChangeset for help on using the changeset viewer.