Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    ra983cbf rc86b08d  
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun 17 18:53:24 2023
    13 // Update Count     : 6347
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Apr  4 14:02:00 2023
     13// Update Count     : 6329
    1414//
    1515
     
    4848using namespace std;
    4949
    50 #include "SynTree/Type.h"                               // for Type
    51 #include "DeclarationNode.h"                            // for DeclarationNode, ...
    52 #include "ExpressionNode.h"                             // for ExpressionNode, ...
    53 #include "InitializerNode.h"                            // for InitializerNode, ...
    54 #include "ParserTypes.h"
    55 #include "StatementNode.h"                              // for build_...
     50#include "SynTree/Declaration.h"
     51#include "ParseNode.h"
    5652#include "TypedefTable.h"
    5753#include "TypeData.h"
     54#include "SynTree/LinkageSpec.h"
    5855#include "Common/SemanticError.h"                                               // error_str
    5956#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
     
    108105        assert( declList );
    109106        // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
    110         DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec );
     107        DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( typeSpec );
    111108        // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
    112109        // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
    113110
    114         for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
     111        for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    115112                cl->cloneBaseType( cur );
    116113        } // for
     
    206203#define NEW_ONE  new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) )
    207204#define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right)
    208 #define MISSING_ANON_FIELD "syntax error, missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
    209 #define MISSING_LOW "syntax error, missing low value for up-to range so index is uninitialized."
    210 #define MISSING_HIGH "syntax error, missing high value for down-to range so index is uninitialized."
     205#define MISSING_ANON_FIELD "Missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
     206#define MISSING_LOW "Missing low value for up-to range so index is uninitialized."
     207#define MISSING_HIGH "Missing high value for down-to range so index is uninitialized."
    211208
    212209static ForCtrl * makeForCtrl(
     
    232229ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    233230        if ( index->initializer ) {
    234                 SemanticError( yylloc, "syntax error, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
     231                SemanticError( yylloc, "Direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
    235232        } // if
    236233        if ( index->next ) {
    237                 SemanticError( yylloc, "syntax error, multiple loop indexes disallowed in for-loop declaration." );
     234                SemanticError( yylloc, "Multiple loop indexes disallowed in for-loop declaration." );
    238235        } // if
    239236        DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) );
     
    260257                        return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
    261258                } else {
    262                         SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
     259                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr;
    263260                } // if
    264261        } else {
    265                 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed. ." ); return nullptr;
     262                SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr;
    266263        } // if
    267264} // forCtrl
    268265
    269266static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) {
    270         SemanticError( yylloc, ::toString( "syntax error, adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"
     267        SemanticError( yylloc, ::toString( "Adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"
    271268                                   "Possible cause is misspelled type name or missing generic parameter." ) );
    272269} // IdentifierBeforeIdentifier
    273270
    274271static void IdentifierBeforeType( string & identifier, const char * kind ) {
    275         SemanticError( yylloc, ::toString( "syntax error, identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
     272        SemanticError( yylloc, ::toString( "Identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
    276273                                   "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) );
    277274} // IdentifierBeforeType
     
    300297%union {
    301298        Token tok;
    302         ExpressionNode * expr;
     299        ParseNode * pn;
     300        ExpressionNode * en;
    303301        DeclarationNode * decl;
    304302        ast::AggregateDecl::Aggregate aggKey;
    305303        ast::TypeDecl::Kind tclass;
    306         StatementNode * stmt;
    307         ClauseNode * clause;
     304        StatementNode * sn;
    308305        ast::WaitForStmt * wfs;
    309     ast::WaitUntilStmt::ClauseNode * wucn;
     306    ast::WaitUntilStmt::ClauseNode * wuscn;
     307        ast::Expr * constant;
    310308        CondCtl * ifctl;
    311         ForCtrl * forctl;
    312         LabelNode * labels;
    313         InitializerNode * init;
    314         OperKinds oper;
     309        ForCtrl * fctl;
     310        OperKinds compop;
     311        LabelNode * label;
     312        InitializerNode * in;
     313        OperKinds op;
    315314        std::string * str;
    316         bool is_volatile;
    317         EnumHiding enum_hiding;
    318         ast::ExceptionKind except_kind;
     315        bool flag;
     316        EnumHiding hide;
     317        ast::ExceptionKind catch_kind;
    319318        ast::GenericExpr * genexpr;
    320319}
     
    382381%type<tok> identifier                                   identifier_at                           identifier_or_type_name         attr_name
    383382%type<tok> quasi_keyword
    384 %type<expr> string_literal
     383%type<constant> string_literal
    385384%type<str> string_literal_list
    386385
    387 %type<enum_hiding> hide_opt                                     visible_hide_opt
     386%type<hide> hide_opt                                    visible_hide_opt
    388387
    389388// expressions
    390 %type<expr> constant
    391 %type<expr> tuple                                                       tuple_expression_list
    392 %type<oper> ptrref_operator                             unary_operator                          assignment_operator                     simple_assignment_operator      compound_assignment_operator
    393 %type<expr> primary_expression                  postfix_expression                      unary_expression
    394 %type<expr> cast_expression_list                        cast_expression                         exponential_expression          multiplicative_expression       additive_expression
    395 %type<expr> shift_expression                            relational_expression           equality_expression
    396 %type<expr> AND_expression                              exclusive_OR_expression         inclusive_OR_expression
    397 %type<expr> logical_AND_expression              logical_OR_expression
    398 %type<expr> conditional_expression              constant_expression                     assignment_expression           assignment_expression_opt
    399 %type<expr> comma_expression                            comma_expression_opt
    400 %type<expr> argument_expression_list_opt        argument_expression_list        argument_expression                     default_initializer_opt
     389%type<en> constant
     390%type<en> tuple                                                 tuple_expression_list
     391%type<op> ptrref_operator                               unary_operator                          assignment_operator                     simple_assignment_operator      compound_assignment_operator
     392%type<en> primary_expression                    postfix_expression                      unary_expression
     393%type<en> cast_expression_list                  cast_expression                         exponential_expression          multiplicative_expression       additive_expression
     394%type<en> shift_expression                              relational_expression           equality_expression
     395%type<en> AND_expression                                exclusive_OR_expression         inclusive_OR_expression
     396%type<en> logical_AND_expression                logical_OR_expression
     397%type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
     398%type<en> comma_expression                              comma_expression_opt
     399%type<en> argument_expression_list_opt  argument_expression_list        argument_expression                     default_initializer_opt
    401400%type<ifctl> conditional_declaration
    402 %type<forctl> for_control_expression            for_control_expression_list
    403 %type<oper> upupeq updown updowneq downupdowneq
    404 %type<expr> subrange
     401%type<fctl> for_control_expression              for_control_expression_list
     402%type<compop> upupeq updown updowneq downupdowneq
     403%type<en> subrange
    405404%type<decl> asm_name_opt
    406 %type<expr> asm_operands_opt                            asm_operands_list                       asm_operand
    407 %type<labels> label_list
    408 %type<expr> asm_clobbers_list_opt
    409 %type<is_volatile> asm_volatile_opt
    410 %type<expr> handler_predicate_opt
     405%type<en> asm_operands_opt                              asm_operands_list                       asm_operand
     406%type<label> label_list
     407%type<en> asm_clobbers_list_opt
     408%type<flag> asm_volatile_opt
     409%type<en> handler_predicate_opt
    411410%type<genexpr> generic_association              generic_assoc_list
    412411
    413412// statements
    414 %type<stmt> statement                                           labeled_statement                       compound_statement
    415 %type<stmt> statement_decl                              statement_decl_list                     statement_list_nodecl
    416 %type<stmt> selection_statement                 if_statement
    417 %type<clause> switch_clause_list_opt            switch_clause_list
    418 %type<expr> case_value
    419 %type<clause> case_clause                               case_value_list                         case_label                                      case_label_list
    420 %type<stmt> iteration_statement                 jump_statement
    421 %type<stmt> expression_statement                        asm_statement
    422 %type<stmt> with_statement
    423 %type<expr> with_clause_opt
    424 %type<stmt> exception_statement
    425 %type<clause> handler_clause                    finally_clause
    426 %type<except_kind> handler_key
    427 %type<stmt> mutex_statement
    428 %type<expr> when_clause                                 when_clause_opt                         waitfor         waituntil               timeout
    429 %type<stmt> waitfor_statement                           waituntil_statement
     413%type<sn> statement                                             labeled_statement                       compound_statement
     414%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
     415%type<sn> selection_statement                   if_statement
     416%type<sn> switch_clause_list_opt                switch_clause_list
     417%type<en> case_value
     418%type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
     419%type<sn> iteration_statement                   jump_statement
     420%type<sn> expression_statement                  asm_statement
     421%type<sn> with_statement
     422%type<en> with_clause_opt
     423%type<sn> exception_statement                   handler_clause                          finally_clause
     424%type<catch_kind> handler_key
     425%type<sn> mutex_statement
     426%type<en> when_clause                                   when_clause_opt                         waitfor         waituntil               timeout
     427%type<sn> waitfor_statement                             waituntil_statement
    430428%type<wfs> wor_waitfor_clause
    431 %type<wucn> waituntil_clause                    wand_waituntil_clause       wor_waituntil_clause
     429%type<wuscn> waituntil_clause                   wand_waituntil_clause       wor_waituntil_clause
    432430
    433431// declarations
     
    441439%type<decl> assertion assertion_list assertion_list_opt
    442440
    443 %type<expr> bit_subrange_size_opt bit_subrange_size
     441%type<en> bit_subrange_size_opt bit_subrange_size
    444442
    445443%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
     
    454452
    455453%type<decl> enumerator_list enum_type enum_type_nobody
    456 %type<init> enumerator_value_opt
     454%type<in> enumerator_value_opt
    457455
    458456%type<decl> external_definition external_definition_list external_definition_list_opt
     
    461459
    462460%type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract
    463 %type<expr> field field_name_list field_name fraction_constants_opt
     461%type<en> field field_name_list field_name fraction_constants_opt
    464462
    465463%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    510508%type<decl> type_parameter type_parameter_list type_initializer_opt
    511509
    512 %type<expr> type_parameters_opt type_list array_type_list
     510%type<en> type_parameters_opt type_list array_type_list
    513511
    514512%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
     
    521519
    522520// initializers
    523 %type<init>  initializer initializer_list_opt initializer_opt
     521%type<in>  initializer initializer_list_opt initializer_opt
    524522
    525523// designators
    526 %type<expr>  designator designator_list designation
     524%type<en>  designator designator_list designation
    527525
    528526
     
    646644
    647645string_literal:
    648         string_literal_list                                                     { $$ = new ExpressionNode( build_constantStr( yylloc, *$1 ) ); }
     646        string_literal_list                                                     { $$ = build_constantStr( yylloc, *$1 ); }
    649647        ;
    650648
     
    689687        // | RESUME '(' comma_expression ')' compound_statement
    690688        //      { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }
    691         | IDENTIFIER IDENTIFIER                                                         // invalid syntax rules
     689        | IDENTIFIER IDENTIFIER                                                         // syntax error
    692690                { IdentifierBeforeIdentifier( *$1.str, *$2.str, "n expression" ); $$ = nullptr; }
    693         | IDENTIFIER type_qualifier                                                     // invalid syntax rules
     691        | IDENTIFIER type_qualifier                                                     // syntax error
    694692                { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; }
    695         | IDENTIFIER storage_class                                                      // invalid syntax rules
     693        | IDENTIFIER storage_class                                                      // syntax error
    696694                { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; }
    697         | IDENTIFIER basic_type_name                                            // invalid syntax rules
     695        | IDENTIFIER basic_type_name                                            // syntax error
    698696                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    699         | IDENTIFIER TYPEDEFname                                                        // invalid syntax rules
     697        | IDENTIFIER TYPEDEFname                                                        // syntax error
    700698                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    701         | IDENTIFIER TYPEGENname                                                        // invalid syntax rules
     699        | IDENTIFIER TYPEGENname                                                        // syntax error
    702700                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    703701        ;
     
    741739                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
    742740        | string_literal '[' assignment_expression ']'          // "abc"[3], 3["abc"]
    743                 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
     741                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); }
    744742        | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call
    745743                {
     
    759757                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
    760758        | string_literal '`' identifier                                         // CFA, postfix call
    761                 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
     759                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }
    762760        | postfix_expression '.' identifier
    763761                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
     
    859857        | constant
    860858        | string_literal
    861                 { $$ = $1; }
     859                { $$ = new ExpressionNode( $1 ); }
    862860        | EXTENSION cast_expression                                                     // GCC
    863861                { $$ = $2->set_extension( true ); }
     
    931929                { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); }
    932930        | '(' RETURN type_no_function ')' cast_expression       // CFA
    933                 { $$ = new ExpressionNode( build_cast( yylloc, $3, $5, ast::CastExpr::Return ) ); }
     931                { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; }
    934932        | '(' COERCE type_no_function ')' cast_expression       // CFA
    935933                { SemanticError( yylloc, "Coerce cast is currently unimplemented." ); $$ = nullptr; }
     
    10401038                // FIX ME: computes $1 twice
    10411039        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    1042                 { $$ = new ExpressionNode( build_cond( yylloc, $1, $1->clone(), $4 ) ); }
     1040                { $$ = new ExpressionNode( build_cond( yylloc, $1, $1, $4 ) ); }
    10431041        ;
    10441042
     
    11521150        identifier_or_type_name ':' attribute_list_opt statement
    11531151                { $$ = $4->add_label( yylloc, $1, $3 ); }
    1154         | identifier_or_type_name ':' attribute_list_opt error // invalid syntax rule
    1155                 {
    1156                         SemanticError( yylloc, ::toString( "syntx error, label \"", *$1.str, "\" must be associated with a statement, "
     1152        | identifier_or_type_name ':' attribute_list_opt error // syntax error
     1153                {
     1154                        SemanticError( yylloc, ::toString( "Label \"", *$1.str, "\" must be associated with a statement, "
    11571155                                                                                           "where a declaration, case, or default is not a statement. "
    11581156                                                                                           "Move the label or terminate with a semi-colon." ) );
     
    11931191        | statement_list_nodecl statement
    11941192                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    1195         | statement_list_nodecl error                                           // invalid syntax rule
    1196                 { SemanticError( yylloc, "syntax error, declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
     1193        | statement_list_nodecl error                                           // syntax error
     1194                { SemanticError( yylloc, "Declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
    11971195        ;
    11981196
     
    12191217                        $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    12201218                }
    1221         | SWITCH '(' comma_expression ')' '{' error '}'         // CFA, invalid syntax rule error
    1222                 { SemanticError( yylloc, "synatx error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
     1219        | SWITCH '(' comma_expression ')' '{' error '}'         // CFA, syntax error
     1220                { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
    12231221        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    12241222                { $$ = new StatementNode( build_switch( yylloc, false, $3, $5 ) ); }
     
    12281226                        $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    12291227                }
    1230         | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, invalid syntax rule
    1231                 { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
     1228        | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, syntax error
     1229                { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
    12321230        ;
    12331231
     
    12621260
    12631261case_value_list:                                                                                // CFA
    1264         case_value                                                                      { $$ = new ClauseNode( build_case( yylloc, $1 ) ); }
     1262        case_value                                                                      { $$ = new StatementNode( build_case( $1 ) ); }
    12651263                // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
    1266         | case_value_list ',' case_value                        { $$ = $1->set_last( new ClauseNode( build_case( yylloc, $3 ) ) ); }
     1264        | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); }
    12671265        ;
    12681266
    12691267case_label:                                                                                             // CFA
    1270         CASE error                                                                                      // invalid syntax rule
    1271                 { SemanticError( yylloc, "syntax error, case list missing after case." ); $$ = nullptr; }
     1268        CASE error                                                                                      // syntax error
     1269                { SemanticError( yylloc, "Missing case list after case." ); $$ = nullptr; }
    12721270        | CASE case_value_list ':'                                      { $$ = $2; }
    1273         | CASE case_value_list error                                            // invalid syntax rule
    1274                 { SemanticError( yylloc, "syntax error, colon missing after case list." ); $$ = nullptr; }
    1275         | DEFAULT ':'                                                           { $$ = new ClauseNode( build_default( yylloc ) ); }
     1271        | CASE case_value_list error                                            // syntax error
     1272                { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; }
     1273        | DEFAULT ':'                                                           { $$ = new StatementNode( build_default( yylloc ) ); }
    12761274                // A semantic check is required to ensure only one default clause per switch/choose statement.
    1277         | DEFAULT error                                                                         //  invalid syntax rules
    1278                 { SemanticError( yylloc, "syntax error, colon missing after default." ); $$ = nullptr; }
     1275        | DEFAULT error                                                                         //  syntax error
     1276                { SemanticError( yylloc, "Missing colon after default." ); $$ = nullptr; }
    12791277        ;
    12801278
    12811279case_label_list:                                                                                // CFA
    12821280        case_label
    1283         | case_label_list case_label                            { $$ = $1->set_last( $2 ); }
     1281        | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_last( $2 )); }
    12841282        ;
    12851283
     
    12981296                { $$ = $1->append_last_case( new StatementNode( build_compound( yylloc, $2 ) ) ); }
    12991297        | switch_clause_list case_label_list statement_list_nodecl
    1300                 { $$ = $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ); }
     1298                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ) ); }
    13011299        ;
    13021300
     
    14051403                        else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    14061404                }
    1407         | comma_expression updowneq comma_expression '~' '@' // CFA, invalid syntax rules
     1405        | comma_expression updowneq comma_expression '~' '@' // CFA, error
    14081406                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    1409         | '@' updowneq '@'                                                                      // CFA, invalid syntax rules
     1407        | '@' updowneq '@'                                                                      // CFA, error
    14101408                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    1411         | '@' updowneq comma_expression '~' '@'                         // CFA, invalid syntax rules
     1409        | '@' updowneq comma_expression '~' '@'                         // CFA, error
    14121410                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    1413         | comma_expression updowneq '@' '~' '@'                         // CFA, invalid syntax rules
     1411        | comma_expression updowneq '@' '~' '@'                         // CFA, error
    14141412                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    1415         | '@' updowneq '@' '~' '@'                                                      // CFA, invalid syntax rules
     1413        | '@' updowneq '@' '~' '@'                                                      // CFA, error
    14161414                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    14171415
     
    14311429                {
    14321430                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1433                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1431                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14341432                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE );
    14351433                }
    1436         | comma_expression ';' '@' updowneq '@'                         // CFA, invalid syntax rules
    1437                 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1434        | comma_expression ';' '@' updowneq '@'                         // CFA, error
     1435                { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    14381436
    14391437        | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA
    14401438                { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), $7 ); }
    1441         | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, invalid syntax rules
     1439        | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, error
    14421440                {
    14431441                        if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
     
    14471445                {
    14481446                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1449                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1447                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14501448                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 );
    14511449                }
    14521450        | comma_expression ';' comma_expression updowneq comma_expression '~' '@' // CFA
    14531451                { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), nullptr ); }
    1454         | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, invalid syntax rules
     1452        | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, error
    14551453                {
    14561454                        if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; }
     
    14601458                {
    14611459                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1462                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1460                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14631461                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr );
    14641462                }
    14651463        | comma_expression ';' '@' updowneq '@' '~' '@' // CFA
    1466                 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1464                { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    14671465
    14681466        | declaration comma_expression                                          // CFA
     
    14811479                {
    14821480                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1483                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1481                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14841482                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE );
    14851483                }
     
    14951493                {
    14961494                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1497                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1495                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14981496                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 );
    14991497                }
     
    15081506                {
    15091507                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1510                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1508                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    15111509                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr );
    15121510                }
    1513         | declaration '@' updowneq '@' '~' '@'                          // CFA, invalid syntax rules
    1514                 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1511        | declaration '@' updowneq '@' '~' '@'                          // CFA, error
     1512                { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    15151513
    15161514        | comma_expression ';' TYPEDEFname                                      // CFA, array type
     
    15211519        | comma_expression ';' downupdowneq TYPEDEFname         // CFA, array type
    15221520                {
    1523                         if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) {
    1524                                 SemanticError( yylloc, "syntax error, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr;
    1525                         }
     1521                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, "All enumation ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; }
    15261522                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
    15271523                }
     
    16181614        MUTEX '(' argument_expression_list_opt ')' statement
    16191615                {
    1620                         if ( ! $3 ) { SemanticError( yylloc, "syntax error, mutex argument list cannot be empty." ); $$ = nullptr; }
     1616                        if ( ! $3 ) { SemanticError( yylloc, "mutex argument list cannot be empty." ); $$ = nullptr; }
    16211617                        $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) );
    16221618                }
     
    16661662                { $$ = build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); }
    16671663        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1668         | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rules
    1669                 { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
     1664        | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
     1665                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    16701666        | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    16711667                { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); }
     
    16831679
    16841680waituntil:
    1685         WAITUNTIL '(' comma_expression ')'
     1681        WAITUNTIL '(' cast_expression ')'
    16861682                { $$ = $3; }
    16871683        ;
     
    17111707                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); }
    17121708        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1713         | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rules
    1714                 { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
     1709        | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
     1710                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    17151711        | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    17161712                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1,
     
    17401736handler_clause:
    17411737        handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
    1742                 { $$ = new ClauseNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }
     1738                { $$ = new StatementNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }
    17431739        | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
    1744                 { $$ = $1->set_last( new ClauseNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }
     1740                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }
    17451741        ;
    17461742
     
    17591755
    17601756finally_clause:
    1761         FINALLY compound_statement                                      { $$ = new ClauseNode( build_finally( yylloc, $2 ) ); }
     1757        FINALLY compound_statement                                      { $$ = new StatementNode( build_finally( yylloc, $2 ) ); }
    17621758        ;
    17631759
     
    18171813asm_operand:                                                                                    // GCC
    18181814        string_literal '(' constant_expression ')'
    1819                 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
     1815                { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", $1, maybeMoveBuild( $3 ) ) ); }
    18201816        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    18211817                {
    1822                         $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, maybeMoveBuild( $4 ), maybeMoveBuild( $6 ) ) );
     1818                        $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, $4, maybeMoveBuild( $6 ) ) );
    18231819                        delete $2.str;
    18241820                }
     
    18291825                { $$ = nullptr; }                                                               // use default argument
    18301826        | string_literal
    1831                 { $$ = $1; }
     1827                { $$ = new ExpressionNode( $1 ); }
    18321828        | asm_clobbers_list_opt ',' string_literal
    1833                 { $$ = (ExpressionNode *)( $1->set_last( $3 ) ); }
     1829                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); }
    18341830        ;
    18351831
     
    19031899static_assert:
    19041900        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    1905                 { $$ = DeclarationNode::newStaticAssert( $3, maybeMoveBuild( $5 ) ); }
     1901                { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
    19061902        | STATICASSERT '(' constant_expression ')' ';'          // CFA
    19071903                { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); }
     
    20672063                        assert( $1->type );
    20682064                        if ( $1->type->qualifiers.any() ) {                     // CV qualifiers ?
    2069                                 SemanticError( yylloc, "syntax error, useless type qualifier(s) in empty declaration." ); $$ = nullptr;
     2065                                SemanticError( yylloc, "Useless type qualifier(s) in empty declaration." ); $$ = nullptr;
    20702066                        }
    20712067                        // enums are never empty declarations because there must have at least one enumeration.
    20722068                        if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ?
    2073                                 SemanticError( yylloc, "syntax error, useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
     2069                                SemanticError( yylloc, "Useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
    20742070                        }
    20752071                }
     
    21022098        | type_declaration_specifier
    21032099        | sue_declaration_specifier
    2104         | sue_declaration_specifier invalid_types                       // invalid syntax rule
    2105                 {
    2106                         SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of ",
     2100        | sue_declaration_specifier invalid_types
     2101                {
     2102                        SemanticError( yylloc, ::toString( "Missing ';' after end of ",
    21072103                                $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ),
    2108                                 " declaration." ) );
     2104                                " declaration" ) );
    21092105                        $$ = nullptr;
    21102106                }
     
    25862582                        // } // for
    25872583                }
    2588         | type_specifier field_declaring_list_opt '}'           // invalid syntax rule
    2589                 {
    2590                         SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of previous declaration." ) );
    2591                         $$ = nullptr;
    2592                 }
    25932584        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
    25942585                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
     
    26892680        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    26902681                {
    2691                         if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) {
    2692                                 SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
    2693                         }
     2682                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() )
     2683                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     2684
    26942685                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 );
    26952686                }
     
    27002691        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    27012692                {
    2702                         if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) {
    2703                                 SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
    2704                         }
     2693                        if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    27052694                        typedefTable.makeTypedef( *$6 );
    27062695                }
     
    31753164        | IDENTIFIER IDENTIFIER
    31763165                { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; }
    3177         | IDENTIFIER type_qualifier                                                     // invalid syntax rules
     3166        | IDENTIFIER type_qualifier                                                     // syntax error
    31783167                { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; }
    3179         | IDENTIFIER storage_class                                                      // invalid syntax rules
     3168        | IDENTIFIER storage_class                                                      // syntax error
    31803169                { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; }
    3181         | IDENTIFIER basic_type_name                                            // invalid syntax rules
     3170        | IDENTIFIER basic_type_name                                            // syntax error
    31823171                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    3183         | IDENTIFIER TYPEDEFname                                                        // invalid syntax rules
     3172        | IDENTIFIER TYPEDEFname                                                        // syntax error
    31843173                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    3185         | IDENTIFIER TYPEGENname                                                        // invalid syntax rules
     3174        | IDENTIFIER TYPEGENname                                                        // syntax error
    31863175                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    31873176        | external_function_definition
     
    32183207        | type_qualifier_list
    32193208                {
    3220                         if ( $1->type->qualifiers.any() ) {
    3221                                 SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
    3222                         }
     3209                        if ( $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    32233210                        if ( $1->type->forall ) forall = true;          // remember generic type
    32243211                }
     
    32313218        | declaration_qualifier_list
    32323219                {
    3233                         if ( $1->type && $1->type->qualifiers.any() ) {
    3234                                 SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
    3235                         }
     3220                        if ( $1->type && $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    32363221                        if ( $1->type && $1->type->forall ) forall = true; // remember generic type
    32373222                }
     
    32443229        | declaration_qualifier_list type_qualifier_list
    32453230                {
    3246                         if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) {
    3247                                 SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
    3248                         }
     3231                        if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    32493232                        if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type
    32503233                }
     
    32773260                        $$ = $3; forall = false;
    32783261                        if ( $5 ) {
    3279                                 SemanticError( yylloc, "syntax error, attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
     3262                                SemanticError( yylloc, "Attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
    32803263                                $$ = nullptr;
    32813264                        } // if
     
    33463329                {
    33473330                        DeclarationNode * name = new DeclarationNode();
    3348                         name->asmName = maybeMoveBuild( $3 );
     3331                        name->asmName = $3;
    33493332                        $$ = name->addQualifiers( $5 );
    33503333                }
Note: See TracChangeset for help on using the changeset viewer.