Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rd48e529 rf9941ff  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Sep 14 23:07:12 2017
    13 // Update Count     : 2815
     12// Last Modified On : Wed Oct 25 12:28:54 2017
     13// Update Count     : 2893
    1414//
    1515
     
    4343#define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time
    4444#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
    45 #define YYERROR_VERBOSE
     45#define YYERROR_VERBOSE                                                                 // more information in syntax errors
    4646
    4747#undef __GNUC_MINOR__
     
    117117bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
    118118
    119 # define YYLLOC_DEFAULT(Cur, Rhs, N)                            \
    120 do                                                              \
    121         if (N) {                                                      \
    122                 (Cur).first_line   = YYRHSLOC(Rhs, 1).first_line;           \
    123                 (Cur).first_column = YYRHSLOC(Rhs, 1).first_column;         \
    124                 (Cur).last_line    = YYRHSLOC(Rhs, N).last_line;            \
    125                 (Cur).last_column  = YYRHSLOC(Rhs, N).last_column;          \
    126                 (Cur).filename     = YYRHSLOC(Rhs, 1).filename;             \
    127         } else {                                                      \
    128                 (Cur).first_line   = (Cur).last_line   =                    \
    129                         YYRHSLOC(Rhs, 0).last_line;                               \
    130                 (Cur).first_column = (Cur).last_column =                    \
    131                         YYRHSLOC(Rhs, 0).last_column;                             \
    132                 (Cur).filename     = YYRHSLOC(Rhs, 0).filename;             \
    133         }                                                             \
    134 while (0)
     119// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     120#define YYLLOC_DEFAULT(Cur, Rhs, N)                                                                                             \
     121if ( N ) {                                                                                                                                              \
     122        (Cur).first_line   = YYRHSLOC( Rhs, 1 ).first_line;                                                     \
     123        (Cur).first_column = YYRHSLOC( Rhs, 1 ).first_column;                                           \
     124        (Cur).last_line    = YYRHSLOC( Rhs, N ).last_line;                                                      \
     125        (Cur).last_column  = YYRHSLOC( Rhs, N ).last_column;                                            \
     126        (Cur).filename     = YYRHSLOC( Rhs, 1 ).filename;                                                       \
     127} else {                                                                                                                                                \
     128        (Cur).first_line   = (Cur).last_line = YYRHSLOC( Rhs, 0 ).last_line;            \
     129        (Cur).first_column = (Cur).last_column = YYRHSLOC( Rhs, 0 ).last_column;        \
     130        (Cur).filename     = YYRHSLOC( Rhs, 0 ).filename;                                                       \
     131}
    135132%}
    136133
    137134%define parse.error verbose
    138135
    139 // Types declaration
     136// Types declaration for productions
    140137%union
    141138{
     
    173170%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    174171%token BOOL COMPLEX IMAGINARY                                                   // C99
     172%token INT128 FLOAT80 FLOAT128                                                  // GCC
    175173%token ZERO_T ONE_T                                                                             // CFA
    176174%token VALIST                                                                                   // GCC
     
    182180%token ATTRIBUTE EXTENSION                                                              // GCC
    183181%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    184 %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
     182%token CHOOSE DISABLE ENABLE FALLTHRU FALLTHROUGH TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
    185183%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    186184%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
     
    252250%type<sn> exception_statement                   handler_clause                          finally_clause
    253251%type<catch_kind> handler_key
     252%type<sn> mutex_statement
    254253%type<en> when_clause                                   when_clause_opt                         waitfor                                         timeout
    255254%type<sn> waitfor_statement
     
    363362%precedence ELSE        // token precedence for start of else clause in IF/WAITFOR statement
    364363
    365 %locations
     364%locations                      // support location tracking for error messages
    366365
    367366%start translation_unit                                                                 // parse-tree root
     
    458457        | '(' compound_statement ')'                                            // GCC, lambda expression
    459458                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
    460         | primary_expression '{' argument_expression_list '}' // CFA, constructor call
    461                 {
    462                         Token fn;
    463                         fn.str = new std::string( "?{}" );                      // location undefined - use location of '{'?
    464                         $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
    465                 }
    466459        | type_name '.' no_attr_identifier                                      // CFA, nested type
    467                 { $$ = nullptr; }                                                               // FIX ME
     460                { throw SemanticError("Qualified names are currently unimplemented."); $$ = nullptr; }                                                          // FIX ME
    468461        | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
    469                 { $$ = nullptr; }                                                               // FIX ME
     462                { throw SemanticError("Qualified names are currently unimplemented."); $$ = nullptr; }                                                          // FIX ME
    470463        ;
    471464
     
    478471                // equivalent to the old x[i,j].
    479472                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
     473        | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
     474                {
     475                        Token fn;
     476                        fn.str = new std::string( "?{}" );                      // location undefined - use location of '{'?
     477                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
     478                }
    480479        | postfix_expression '(' argument_expression_list ')'
    481480                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
     
    809808        | jump_statement
    810809        | with_statement
     810        | mutex_statement
    811811        | waitfor_statement
    812812        | exception_statement
     
    974974        ;
    975975
     976fall_through_name:                                                                              // CFA
     977        FALLTHRU
     978        | FALLTHROUGH
     979        ;
     980
    976981fall_through:                                                                                   // CFA
    977         FALLTHRU
     982        fall_through_name
    978983                { $$ = nullptr; }
    979         | FALLTHRU ';'
     984        | fall_through_name ';'
    980985                { $$ = nullptr; }
    981986        ;
     
    10331038        ;
    10341039
     1040// If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex".
     1041mutex_statement:
     1042        MUTEX '(' argument_expression_list ')' statement
     1043                { $$ = nullptr; }                                                               // FIX ME
     1044        ;
     1045
    10351046when_clause:
    10361047        WHEN '(' comma_expression ')'
     
    15511562        | VOLATILE
    15521563                { $$ = DeclarationNode::newTypeQualifier( Type::Volatile ); }
    1553         | MUTEX
    1554                 { $$ = DeclarationNode::newTypeQualifier( Type::Mutex ); }
    15551564        | ATOMIC
    15561565                { $$ = DeclarationNode::newTypeQualifier( Type::Atomic ); }
     
    16061615
    16071616basic_type_name:
    1608         CHAR
     1617        VOID
     1618                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     1619        | BOOL                                                                                          // C99
     1620                { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
     1621        | CHAR
    16091622                { $$ = DeclarationNode::newBasicType( DeclarationNode::Char ); }
     1623        | INT
     1624                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
     1625        | INT128
     1626                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 ); }
     1627        | FLOAT
     1628                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
     1629        | FLOAT80
     1630                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float80 ); }
     1631        | FLOAT128
     1632                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float128 ); }
    16101633        | DOUBLE
    16111634                { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); }
    1612         | FLOAT
    1613                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
    1614         | INT
    1615                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
    1616         | LONG
    1617                 { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
    1618         | SHORT
    1619                 { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
     1635        | COMPLEX                                                                                       // C99
     1636                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
     1637        | IMAGINARY                                                                                     // C99
     1638                { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
    16201639        | SIGNED
    16211640                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }
    16221641        | UNSIGNED
    16231642                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }
    1624         | VOID
    1625                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
    1626         | BOOL                                                                                          // C99
    1627                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
    1628         | COMPLEX                                                                                       // C99
    1629                 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
    1630         | IMAGINARY                                                                                     // C99
    1631                 { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
     1643        | SHORT
     1644                { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
     1645        | LONG
     1646                { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
    16321647        | ZERO_T
    16331648                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
     
    24762491        | TYPEDEFname
    24772492        | TYPEGENname
     2493        | FALLTHROUGH
     2494                { $$ = Token{ new string( "fallthrough" ), { nullptr, -1 } }; }
    24782495        | CONST
    24792496                { $$ = Token{ new string( "__const__" ), { nullptr, -1 } }; }
     
    26992716        paren_identifier attribute_list_opt
    27002717                { $$ = $1->addQualifiers( $2 ); }
     2718        | '&' MUTEX paren_identifier attribute_list_opt
     2719                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( Type::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
    27012720        | identifier_parameter_ptr
    27022721        | identifier_parameter_array attribute_list_opt
     
    27392758//
    27402759//              typedef int foo;
     2760//              forall( otype T ) struct foo;
    27412761//              int f( int foo ); // redefine typedef name in new scope
    27422762//
     
    27462766        typedef attribute_list_opt
    27472767                { $$ = $1->addQualifiers( $2 ); }
     2768        | '&' MUTEX typedef attribute_list_opt
     2769                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( Type::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
    27482770        | type_parameter_ptr
    27492771        | type_parameter_array attribute_list_opt
     
    28922914abstract_parameter_declarator:
    28932915        abstract_parameter_ptr
     2916        | '&' MUTEX attribute_list_opt
     2917                { $$ = DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( Type::Mutex ), OperKinds::AddressOf )->addQualifiers( $3 ); }
    28942918        | abstract_parameter_array attribute_list_opt
    28952919                { $$ = $1->addQualifiers( $2 ); }
Note: See TracChangeset for help on using the changeset viewer.