Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rea0c5e3 re612146c  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 11 18:12:00 2017
    13 // Update Count     : 2787
     12// Last Modified On : Sun Sep  3 20:43:19 2017
     13// Update Count     : 2742
    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
    4645
    4746#undef __GNUC_MINOR__
     
    6362stack< LinkageSpec::Spec > linkageStack;
    6463
    65 bool 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;
     64void 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 ) );
    9567} // appendStr
    9668
     
    11688bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
    11789%}
    118 
    119 %define parse.error verbose
    12090
    12191// Types declaration
     
    176146// overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
    177147// converted into the tuple index (.)(1). e.g., 3.x
    178 %token<tok>     FLOATING_DECIMALconstant        FLOATING_FRACTIONconstant       FLOATINGconstant
     148%token<tok>     REALDECIMALconstant     REALFRACTIONconstant    FLOATINGconstant
    179149
    180150// multi-character operators
     
    345315%precedence ELSE        // token precedence for start of else clause in IF/WAITFOR statement
    346316
    347 
    348317%start translation_unit                                                                 // parse-tree root
    349318
     
    352321
    353322// The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
    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.
     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.
    357326//
    358327// Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
     
    391360                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
    392361        INTEGERconstant                                                         { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
    393         | FLOATING_DECIMALconstant                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    394         | FLOATING_FRACTIONconstant                                     { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
     362        | REALDECIMALconstant                                           { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
     363        | REALFRACTIONconstant                                          { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    395364        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    396365        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
     
    421390        | string_literal_list STRINGliteral
    422391                {
    423                         if ( ! appendStr( *$1, *$2 ) ) YYERROR;         // append 2nd juxtaposed string to 1st
     392                        appendStr( $1, $2 );                                            // append 2nd juxtaposed string to 1st
    424393                        delete $2;                                                                      // allocated by lexer
    425394                        $$ = $1;                                                                        // conversion from tok to str
     
    465434        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
    466435                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
    467         | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    468                 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
     436        | postfix_expression REALFRACTIONconstant                       // CFA, tuple index
     437                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_REALFRACTIONconstant( *$2 ) ) ); }
    469438        | postfix_expression ARROW no_attr_identifier
    470439                {
     
    510479field:                                                                                                  // CFA, tuple field selector
    511480        field_name
    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 ) ) ); }
     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 ) ) ); }
    516485        | field_name '.' field
    517486                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
     
    538507        // empty
    539508                { $$ = nullptr; }
    540         | fraction_constants FLOATING_FRACTIONconstant
    541                 {
    542                         Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 );
     509        | fraction_constants REALFRACTIONconstant
     510                {
     511                        Expression * constant = build_field_name_REALFRACTIONconstant( *$2 );
    543512                        $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1,  constant ) ) : new ExpressionNode( constant );
    544513                }
Note: See TracChangeset for help on using the changeset viewer.