Changeset b3c7963 for src/Parser/parser.yy
- Timestamp:
- Sep 12, 2017, 5:55:31 PM (7 years ago)
- 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:
- 4639b0d
- Parents:
- a506df4 (diff), a46478a (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
ra506df4 rb3c7963 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 30 07:04:19201713 // Update Count : 27 4012 // Last Modified On : Mon Sep 11 18:12:00 2017 13 // Update Count : 2787 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_VERBOSE 45 46 46 47 #undef __GNUC_MINOR__ … … 62 63 stack< LinkageSpec::Spec > linkageStack; 63 64 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 ) ); 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; 67 95 } // appendStr 68 96 … … 89 117 %} 90 118 119 %define parse.error verbose 120 91 121 // Types declaration 92 122 %union … … 100 130 StatementNode * sn; 101 131 WaitForStmt * wfs; 102 ConstantExpr* constant;132 Expression * constant; 103 133 IfCtl * ifctl; 104 134 ForCtl * fctl; … … 146 176 // overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically 147 177 // converted into the tuple index (.)(1). e.g., 3.x 148 %token<tok> REALDECIMALconstant REALFRACTIONconstant FLOATINGconstant178 %token<tok> FLOATING_DECIMALconstant FLOATING_FRACTIONconstant FLOATINGconstant 149 179 150 180 // multi-character operators … … 315 345 %precedence ELSE // token precedence for start of else clause in IF/WAITFOR statement 316 346 347 317 348 %start translation_unit // parse-tree root 318 349 … … 321 352 322 353 // 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-free324 // grammar, such a grammar would obscure the relationship between syntactic and semantic constructs. Hence, this325 // 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. 326 357 // 327 358 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those … … 360 391 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 361 392 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 ) ); } 364 395 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 365 396 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 ) ); } … … 390 421 | string_literal_list STRINGliteral 391 422 { 392 appendStr( $1, $2 );// append 2nd juxtaposed string to 1st423 if ( ! appendStr( *$1, *$2 ) ) YYERROR; // append 2nd juxtaposed string to 1st 393 424 delete $2; // allocated by lexer 394 425 $$ = $1; // conversion from tok to str … … 434 465 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 435 466 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); } 436 | postfix_expression REALFRACTIONconstant// CFA, tuple index437 { $$ = 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 ) ) ); } 438 469 | postfix_expression ARROW no_attr_identifier 439 470 { … … 479 510 field: // CFA, tuple field selector 480 511 field_name 481 | REALDECIMALconstant field482 { $$ = 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 ) ) ); } 485 516 | field_name '.' field 486 517 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } … … 507 538 // empty 508 539 { $$ = nullptr; } 509 | fraction_constants REALFRACTIONconstant510 { 511 Expression * constant = build_field_name_ REALFRACTIONconstant( *$2 );540 | fraction_constants FLOATING_FRACTIONconstant 541 { 542 Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 ); 512 543 $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1, constant ) ) : new ExpressionNode( constant ); 513 544 }
Note: See TracChangeset
for help on using the changeset viewer.