Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r2037f82 re82aa9df  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 18 23:49:10 2016
    13 // Update Count     : 1909
     12// Last Modified On : Mon Aug 15 15:18:19 2016
     13// Update Count     : 1891
    1414//
    1515
     
    4343#define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time
    4444#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
     45extern char *yytext;
    4546
    4647#undef __GNUC_MINOR__
     
    5556#include "LinkageSpec.h"
    5657
    57 extern DeclarationNode * parseTree;
    58 extern LinkageSpec::Spec linkage;
    59 extern TypedefTable typedefTable;
    60 
    61 std::stack< LinkageSpec::Spec > linkageStack;
     58DeclarationNode *theTree = 0;                                                   // the resulting parse tree
     59LinkageSpec::Type linkage = LinkageSpec::Cforall;
     60std::stack< LinkageSpec::Type > linkageStack;
     61TypedefTable typedefTable;
    6262
    6363void appendStr( std::string &to, std::string *from ) {
     
    223223%type<decl> paren_identifier paren_type
    224224
    225 %type<decl> storage_class storage_class_list
     225%type<decl> storage_class storage_class_name 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( assign_strptr($1) ) ); }
    314         | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( assign_strptr($1) ) ); }
    315         | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( assign_strptr($1) ) ); }
     313INTEGERconstant                                                                 { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
     314        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
     315        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
    316316        ;
    317317
     
    338338
    339339string_literal_list:                                                                    // juxtaposed strings are concatenated
    340         STRINGliteral                                                           { $$ = build_constantStr( assign_strptr($1) ); }
     340        STRINGliteral                                                           { $$ = build_constantStr( *$1 ); }
    341341        | string_literal_list STRINGliteral
    342342                {
     
    699699        | EXTENSION declaration                                                         // GCC
    700700                {       // mark all fields in list
    701                         for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
     701                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
    702702                                iter->set_extension( true );
    703703                        $$ = new StatementNode( $2 );
     
    838838jump_statement:
    839839        GOTO IDENTIFIER ';'
    840                 { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Goto ) ); }
     840                { $$ = new StatementNode( build_branch( *$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( assign_strptr($2), BranchStmt::Continue ) ); }
     851                { $$ = new StatementNode( build_branch( *$2, BranchStmt::Continue ) ); delete $2; }
    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( assign_strptr($2), BranchStmt::Break ) ); }
     858                { $$ = new StatementNode( build_branch( *$2, BranchStmt::Break ) ); delete $2; }
    859859        | RETURN comma_expression_opt ';'
    860860                { $$ = new StatementNode( build_return( $2 ) ); }
     
    979979label_list:
    980980        no_attr_identifier
    981                 { $$ = new LabelNode(); $$->labels.push_back( assign_strptr($1) ); }
     981                { $$ = new LabelNode(); $$->labels.push_back( *$1 ); }
    982982        | label_list ',' no_attr_identifier
    983                 { $$ = $1; $1->labels.push_back( assign_strptr($3) ); }
     983                { $$ = $1; $1->labels.push_back( *$3 ); }
    984984        ;
    985985
     
    13241324
    13251325storage_class:
     1326        storage_class_name
     1327        ;
     1328
     1329storage_class_name:
    13261330        EXTERN
    13271331                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Extern ); }
     
    14931497        | EXTENSION field_declaring_list ';'                            // GCC
    14941498                {       // mark all fields in list
    1495                         for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
     1499                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
    14961500                                iter->set_extension( true );
    14971501                        $$ = $2;
     
    19701974                {}                                                                                              // empty input file
    19711975        | external_definition_list
    1972                 { parseTree = parseTree != nullptr ? parseTree->appendList( $1 ) : $1;  }
     1976                {
     1977                        if ( theTree ) {
     1978                                theTree->appendList( $1 );
     1979                        } else {
     1980                                theTree = $1;
     1981                        }
     1982                }
    19731983        ;
    19741984
     
    19761986        external_definition
    19771987        | external_definition_list push external_definition
    1978                 { $$ = $1 != nullptr ? $1->appendList( $3 ) : $3; }
     1988                { $$ = ( $1 != NULL ) ? $1->appendList( $3 ) : $3; }
    19791989        ;
    19801990
     
    19922002        | EXTERN STRINGliteral
    19932003                {
    1994                         linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    1995                         linkage = LinkageSpec::fromString( assign_strptr($2) );
     2004                        linkageStack.push( linkage );
     2005                        linkage = LinkageSpec::fromString( *$2 );
    19962006                }
    19972007          '{' external_definition_list_opt '}'                          // C++-style linkage specifier
     
    20032013        | EXTENSION external_definition
    20042014                {       // mark all fields in list
    2005                         for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )
     2015                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
    20062016                                iter->set_extension( true );
    20072017                        $$ = $2;
     
    21372147
    21382148any_word:                                                                                               // GCC
    2139         identifier_or_type_name { delete $1; }
    2140         | storage_class { delete $1; }
    2141         | basic_type_name { delete $1; }
    2142         | type_qualifier { delete $1; }
     2149        identifier_or_type_name {}
     2150        | storage_class_name {}
     2151        | basic_type_name {}
     2152        | type_qualifier {}
    21432153        ;
    21442154
     
    28382848// ----end of grammar----
    28392849
    2840 extern char *yytext;
    2841 
    28422850void yyerror( const char * ) {
    28432851        std::cout << "Error ";
Note: See TracChangeset for help on using the changeset viewer.