Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    re82aa9df r2037f82  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 15 15:18:19 2016
    13 // Update Count     : 1891
     12// Last Modified On : Thu Aug 18 23:49:10 2016
     13// Update Count     : 1909
    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 extern char *yytext;
    4645
    4746#undef __GNUC_MINOR__
     
    5655#include "LinkageSpec.h"
    5756
    58 DeclarationNode *theTree = 0;                                                   // the resulting parse tree
    59 LinkageSpec::Type linkage = LinkageSpec::Cforall;
    60 std::stack< LinkageSpec::Type > linkageStack;
    61 TypedefTable typedefTable;
     57extern DeclarationNode * parseTree;
     58extern LinkageSpec::Spec linkage;
     59extern TypedefTable typedefTable;
     60
     61std::stack< LinkageSpec::Spec > linkageStack;
    6262
    6363void appendStr( std::string &to, std::string *from ) {
     
    223223%type<decl> paren_identifier paren_type
    224224
    225 %type<decl> storage_class storage_class_name storage_class_list
     225%type<decl> storage_class storage_class_list
    226226
    227227%type<decl> sue_declaration_specifier sue_type_specifier
     
    311311constant:
    312312                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
    313 INTEGERconstant                                                                 { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
    314         | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    315         | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
     313        INTEGERconstant                                                                 { $$ = new ExpressionNode( build_constantInteger( assign_strptr($1) ) ); }
     314        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( assign_strptr($1) ) ); }
     315        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( assign_strptr($1) ) ); }
    316316        ;
    317317
     
    338338
    339339string_literal_list:                                                                    // juxtaposed strings are concatenated
    340         STRINGliteral                                                           { $$ = build_constantStr( *$1 ); }
     340        STRINGliteral                                                           { $$ = build_constantStr( assign_strptr($1) ); }
    341341        | string_literal_list STRINGliteral
    342342                {
     
    699699        | EXTENSION declaration                                                         // GCC
    700700                {       // mark all fields in list
    701                         for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
     701                        for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
    702702                                iter->set_extension( true );
    703703                        $$ = new StatementNode( $2 );
     
    838838jump_statement:
    839839        GOTO IDENTIFIER ';'
    840                 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Goto ) ); }
     840                { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Goto ) ); }
    841841        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
    842842                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
     
    849849                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    850850                // the target of the transfer appears only at the start of an iteration statement.
    851                 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Continue ) ); delete $2; }
     851                { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Continue ) ); }
    852852        | BREAK ';'
    853853                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
     
    856856                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    857857                // the target of the transfer appears only at the start of an iteration statement.
    858                 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Break ) ); delete $2; }
     858                { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Break ) ); }
    859859        | RETURN comma_expression_opt ';'
    860860                { $$ = new StatementNode( build_return( $2 ) ); }
     
    979979label_list:
    980980        no_attr_identifier
    981                 { $$ = new LabelNode(); $$->labels.push_back( *$1 ); }
     981                { $$ = new LabelNode(); $$->labels.push_back( assign_strptr($1) ); }
    982982        | label_list ',' no_attr_identifier
    983                 { $$ = $1; $1->labels.push_back( *$3 ); }
     983                { $$ = $1; $1->labels.push_back( assign_strptr($3) ); }
    984984        ;
    985985
     
    13241324
    13251325storage_class:
    1326         storage_class_name
    1327         ;
    1328 
    1329 storage_class_name:
    13301326        EXTERN
    13311327                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Extern ); }
     
    14971493        | EXTENSION field_declaring_list ';'                            // GCC
    14981494                {       // mark all fields in list
    1499                         for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
     1495                        for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
    15001496                                iter->set_extension( true );
    15011497                        $$ = $2;
     
    19741970                {}                                                                                              // empty input file
    19751971        | external_definition_list
    1976                 {
    1977                         if ( theTree ) {
    1978                                 theTree->appendList( $1 );
    1979                         } else {
    1980                                 theTree = $1;
    1981                         }
    1982                 }
     1972                { parseTree = parseTree != nullptr ? parseTree->appendList( $1 ) : $1;  }
    19831973        ;
    19841974
     
    19861976        external_definition
    19871977        | external_definition_list push external_definition
    1988                 { $$ = ( $1 != NULL ) ? $1->appendList( $3 ) : $3; }
     1978                { $$ = $1 != nullptr ? $1->appendList( $3 ) : $3; }
    19891979        ;
    19901980
     
    20021992        | EXTERN STRINGliteral
    20031993                {
    2004                         linkageStack.push( linkage );
    2005                         linkage = LinkageSpec::fromString( *$2 );
     1994                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
     1995                        linkage = LinkageSpec::fromString( assign_strptr($2) );
    20061996                }
    20071997          '{' external_definition_list_opt '}'                          // C++-style linkage specifier
     
    20132003        | EXTENSION external_definition
    20142004                {       // mark all fields in list
    2015                         for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
     2005                        for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
    20162006                                iter->set_extension( true );
    20172007                        $$ = $2;
     
    21472137
    21482138any_word:                                                                                               // GCC
    2149         identifier_or_type_name {}
    2150         | storage_class_name {}
    2151         | basic_type_name {}
    2152         | type_qualifier {}
     2139        identifier_or_type_name { delete $1; }
     2140        | storage_class { delete $1; }
     2141        | basic_type_name { delete $1; }
     2142        | type_qualifier { delete $1; }
    21532143        ;
    21542144
     
    28482838// ----end of grammar----
    28492839
     2840extern char *yytext;
     2841
    28502842void yyerror( const char * ) {
    28512843        std::cout << "Error ";
Note: See TracChangeset for help on using the changeset viewer.