Changes in src/Parser/parser.yy [ea0c5e3:e612146c]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rea0c5e3 re612146c 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 11 18:12:00201713 // Update Count : 27 8712 // Last Modified On : Sun Sep 3 20:43:19 2017 13 // Update Count : 2742 14 14 // 15 15 … … 43 43 #define YYDEBUG_LEXER_TEXT (yylval) // lexer loads this up each time 44 44 #define YYDEBUG 1 // get the pretty debugging code to compile 45 #define YYERROR_VERBOSE46 45 47 46 #undef __GNUC_MINOR__ … … 63 62 stack< LinkageSpec::Spec > linkageStack; 64 63 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; 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 ) ); 95 67 } // appendStr 96 68 … … 116 88 bool forall = false; // aggregate have one or more forall qualifiers ? 117 89 %} 118 119 %define parse.error verbose120 90 121 91 // Types declaration … … 176 146 // overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically 177 147 // converted into the tuple index (.)(1). e.g., 3.x 178 %token<tok> FLOATING_DECIMALconstant FLOATING_FRACTIONconstant FLOATINGconstant148 %token<tok> REALDECIMALconstant REALFRACTIONconstant FLOATINGconstant 179 149 180 150 // multi-character operators … … 345 315 %precedence ELSE // token precedence for start of else clause in IF/WAITFOR statement 346 316 347 348 317 %start translation_unit // parse-tree root 349 318 … … 352 321 353 322 // 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 purely355 // context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.356 // Hence, thisgrammar 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. 357 326 // 358 327 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those … … 391 360 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 392 361 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 ) ); } 395 364 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 396 365 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 ) ); } … … 421 390 | string_literal_list STRINGliteral 422 391 { 423 if ( ! appendStr( *$1, *$2 ) ) YYERROR;// append 2nd juxtaposed string to 1st392 appendStr( $1, $2 ); // append 2nd juxtaposed string to 1st 424 393 delete $2; // allocated by lexer 425 394 $$ = $1; // conversion from tok to str … … 465 434 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 466 435 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); } 467 | postfix_expression FLOATING_FRACTIONconstant// CFA, tuple index468 { $$ = 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 ) ) ); } 469 438 | postfix_expression ARROW no_attr_identifier 470 439 { … … 510 479 field: // CFA, tuple field selector 511 480 field_name 512 | FLOATING_DECIMALconstant field513 { $$ = 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 ) ) ); } 516 485 | field_name '.' field 517 486 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } … … 538 507 // empty 539 508 { $$ = nullptr; } 540 | fraction_constants FLOATING_FRACTIONconstant541 { 542 Expression * constant = build_field_name_ FLOATING_FRACTIONconstant( *$2 );509 | fraction_constants REALFRACTIONconstant 510 { 511 Expression * constant = build_field_name_REALFRACTIONconstant( *$2 ); 543 512 $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1, constant ) ) : new ExpressionNode( constant ); 544 513 }
Note:
See TracChangeset
for help on using the changeset viewer.