Ignore:
Timestamp:
Sep 13, 2017, 2:44:01 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
ba54f7d, c935c3a
Parents:
e3e16bc (diff), 7dc09294 (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

    re3e16bc r982832e  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep  3 20:43:19 2017
    13 // Update Count     : 2742
     12// Last Modified On : Mon Sep 11 18:12:00 2017
     13// Update Count     : 2787
    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
    4546
    4647#undef __GNUC_MINOR__
     
    6263stack< LinkageSpec::Spec > linkageStack;
    6364
    64 void appendStr( string *to, string *from ) {
    65         // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
    66         to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
     65bool appendStr( string & to, string & from ) {
     66        // 1. Multiple strings are concatenated into a single string but not combined internally. The reason is that
     67        //    "\x12" "3" is treated as 2 characters versus 1 because "escape sequences are converted into single members of
     68        //    the execution character set just prior to adjacent string literal concatenation" (C11, Section 6.4.5-8). It is
     69        //    easier to let the C compiler handle this case.
     70        //
     71        // 2. String encodings are transformed into canonical form (one encoding at start) so the encoding can be found
     72        //    without searching the string, e.g.: "abc" L"def" L"ghi" => L"abc" "def" "ghi". Multiple encodings must match,
     73        //    i.e., u"a" U"b" L"c" is disallowed.
     74
     75        if ( from[0] != '"' ) {                                                         // encoding ?
     76                if ( to[0] != '"' ) {                                                   // encoding ?
     77                        if ( to[0] != from[0] || to[1] != from[1] ) { // different encodings ?
     78                                yyerror( "non-matching string encodings for string-literal concatenation" );
     79                                return false;                                                   // parse error, must call YYERROR in action
     80                        } else if ( from[1] == '8' ) {
     81                                from.erase( 0, 1 );                                             // remove 2nd encoding
     82                        } // if
     83                } else {
     84                        if ( from[1] == '8' ) {                                         // move encoding to start
     85                                to = "u8" + to;
     86                                from.erase( 0, 1 );                                             // remove 2nd encoding
     87                        } else {
     88                                to = from[0] + to;
     89                        } // if
     90                } // if
     91                from.erase( 0, 1 );                                                             // remove 2nd encoding
     92        } // if
     93        to += " " + from;                                                                       // concatenated into single string
     94        return true;
    6795} // appendStr
    6896
     
    88116bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
    89117%}
     118
     119%define parse.error verbose
    90120
    91121// Types declaration
     
    146176// overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
    147177// converted into the tuple index (.)(1). e.g., 3.x
    148 %token<tok>     REALDECIMALconstant     REALFRACTIONconstant    FLOATINGconstant
     178%token<tok>     FLOATING_DECIMALconstant        FLOATING_FRACTIONconstant       FLOATINGconstant
    149179
    150180// multi-character operators
     
    315345%precedence ELSE        // token precedence for start of else clause in IF/WAITFOR statement
    316346
     347
    317348%start translation_unit                                                                 // parse-tree root
    318349
     
    321352
    322353// The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
    323 // "identifier" and "TYPEDEFname" that are lexically identical.  While it is possible to write a purely context-free
    324 // grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.  Hence, this
    325 // grammar uses the ANSI style.
     354// "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical.  While it is possible to write a purely
     355// context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.
     356// Hence, this grammar uses the ANSI style.
    326357//
    327358// Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
     
    360391                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
    361392        INTEGERconstant                                                         { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
    362         | REALDECIMALconstant                                           { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    363         | REALFRACTIONconstant                                          { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
     393        | FLOATING_DECIMALconstant                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
     394        | FLOATING_FRACTIONconstant                                     { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    364395        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    365396        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
     
    390421        | string_literal_list STRINGliteral
    391422                {
    392                         appendStr( $1, $2 );                                            // append 2nd juxtaposed string to 1st
     423                        if ( ! appendStr( *$1, *$2 ) ) YYERROR;         // append 2nd juxtaposed string to 1st
    393424                        delete $2;                                                                      // allocated by lexer
    394425                        $$ = $1;                                                                        // conversion from tok to str
     
    434465        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
    435466                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
    436         | postfix_expression REALFRACTIONconstant                       // CFA, tuple index
    437                 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_REALFRACTIONconstant( *$2 ) ) ); }
     467        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
     468                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    438469        | postfix_expression ARROW no_attr_identifier
    439470                {
     
    479510field:                                                                                                  // CFA, tuple field selector
    480511        field_name
    481         | REALDECIMALconstant field
    482                 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_REALDECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    483         | REALDECIMALconstant '[' push field_list pop ']'
    484                 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_REALDECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }
     512        | FLOATING_DECIMALconstant field
     513                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
     514        | FLOATING_DECIMALconstant '[' push field_list pop ']'
     515                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }
    485516        | field_name '.' field
    486517                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
     
    507538        // empty
    508539                { $$ = nullptr; }
    509         | fraction_constants REALFRACTIONconstant
    510                 {
    511                         Expression * constant = build_field_name_REALFRACTIONconstant( *$2 );
     540        | fraction_constants FLOATING_FRACTIONconstant
     541                {
     542                        Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 );
    512543                        $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1,  constant ) ) : new ExpressionNode( constant );
    513544                }
Note: See TracChangeset for help on using the changeset viewer.