Changeset 90152a4 for src/Parser/lex.ll
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (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
-
src/Parser/lex.ll (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/lex.ll
rf9feab8 r90152a4 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Wed Oct 25 13:53:56 201713 * Update Count : 6 3412 * Last Modified On : Wed Aug 8 17:23:17 2018 13 * Update Count : 685 14 14 */ 15 15 … … 25 25 //**************************** Includes and Defines **************************** 26 26 27 // trigger before each matching rule's action 28 #define YY_USER_ACTION \ 29 yylloc.first_line = yylineno; \ 30 yylloc.first_column = column; \ 31 column += yyleng; \ 32 yylloc.last_column = column; \ 33 yylloc.last_line = yylineno; \ 34 yylloc.filename = yyfilename ? yyfilename : ""; 27 35 unsigned int column = 0; // position of the end of the last token parsed 28 #define YY_USER_ACTION yylloc.first_line = yylineno; yylloc.first_column = column; column += yyleng; yylloc.last_column = column; yylloc.last_line = yylineno; yylloc.filename = yyfilename ? yyfilename : ""; // trigger before each matching rule's action29 36 30 37 #include <string> … … 49 56 #define NUMERIC_RETURN(x) rm_underscore(); RETURN_VAL( x ) // numeric constant 50 57 #define KEYWORD_RETURN(x) RETURN_CHAR( x ) // keyword 51 #define QKEYWORD_RETURN(x) typedefTable.isKind( yytext ); RETURN_VAL(x);// quasi-keyword58 #define QKEYWORD_RETURN(x) RETURN_VAL(x); // quasi-keyword 52 59 #define IDENTIFIER_RETURN() RETURN_VAL( typedefTable.isKind( yytext ) ) 53 60 #define ATTRIBUTE_RETURN() RETURN_VAL( ATTR_IDENTIFIER ) 54 61 55 62 void rm_underscore() { 56 // Remove underscores in numeric constant by copying the non-underscore characters to the front of the string.63 // SKULLDUGGERY: remove underscores (ok to shorten?) 57 64 yyleng = 0; 58 for ( int i = 0; yytext[i] != '\0'; i += 1 ) { 59 if ( yytext[i] == '`' ) { 60 // copy user suffix 61 for ( ; yytext[i] != '\0'; i += 1 ) { 62 yytext[yyleng] = yytext[i]; 63 yyleng += 1; 64 } // for 65 break; 66 } // if 65 for ( int i = 0; yytext[i] != '\0'; i += 1 ) { // copying non-underscore characters to front of string 67 66 if ( yytext[i] != '_' ) { 68 67 yytext[yyleng] = yytext[i]; … … 71 70 } // for 72 71 yytext[yyleng] = '\0'; 73 } 72 } // rm_underscore 74 73 75 74 // Stop warning due to incorrectly generated flex code. … … 77 76 %} 78 77 78 binary [0-1] 79 79 octal [0-7] 80 80 nonzero [1-9] … … 89 89 attr_identifier "@"{identifier} 90 90 91 user_suffix_opt ("`"{identifier})?92 93 91 // numeric constants, CFA: '_' in constant 94 92 hex_quad {hex}("_"?{hex}){3} 95 93 size_opt (8|16|32|64|128)? 96 94 length ("ll"|"LL"|[lL]{size_opt})|("hh"|"HH"|[hH]) 97 integer_suffix_opt ("_"?(([uU]({length}?[iI]?)|([iI]{length}))|([iI]({length}?[uU]?)|([uU]{length}))|({length}([iI]?[uU]?)|([uU][iI]))|[zZ]))? {user_suffix_opt}95 integer_suffix_opt ("_"?(([uU]({length}?[iI]?)|([iI]{length}))|([iI]({length}?[uU]?)|([uU]{length}))|({length}([iI]?[uU]?)|([uU][iI]))|[zZ]))? 98 96 99 97 octal_digits ({octal})|({octal}({octal}|"_")*{octal}) … … 103 101 nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal}) 104 102 decimal_constant {nonzero_digits}{integer_suffix_opt} 103 104 binary_digits ({binary})|({binary}({binary}|"_")*{binary}) 105 binary_prefix "0"[bB]"_"? 106 binary_constant {binary_prefix}{binary_digits}{integer_suffix_opt} 105 107 106 108 hex_digits ({hex})|({hex}({hex}|"_")*{hex}) … … 113 115 floating_length ([fFdDlL]|[lL]{floating_size}) 114 116 floating_suffix ({floating_length}?[iI]?)|([iI]{floating_length}) 115 floating_suffix_opt ("_"?({floating_suffix}|"DL"))? {user_suffix_opt}117 floating_suffix_opt ("_"?({floating_suffix}|"DL"))? 116 118 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 117 119 floating_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt} … … 120 122 121 123 binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits} 122 hex_floating_suffix_opt ("_"?({floating_suffix}))? {user_suffix_opt}124 hex_floating_suffix_opt ("_"?({floating_suffix}))? 123 125 hex_floating_fraction ({hex_digits}?"."{hex_digits})|({hex_digits}".") 124 126 hex_floating_constant {hex_prefix}(({hex_floating_fraction}{binary_exponent})|({hex_digits}{binary_exponent})){hex_floating_suffix_opt} … … 179 181 } 180 182 181 /* ignore preprocessor directives (for now)*/182 ^{h_white}*"#"[^\n]*"\n" ;183 /* preprocessor-style directives */ 184 ^{h_white}*"#"[^\n]*"\n" { RETURN_VAL( DIRECTIVE ); } 183 185 184 186 /* ignore C style comments (ALSO HANDLED BY CPP) */ … … 203 205 __asm { KEYWORD_RETURN(ASM); } // GCC 204 206 __asm__ { KEYWORD_RETURN(ASM); } // GCC 205 _At { KEYWORD_RETURN(AT); } // CFA206 207 _Atomic { KEYWORD_RETURN(ATOMIC); } // C11 207 208 __attribute { KEYWORD_RETURN(ATTRIBUTE); } // GCC … … 232 233 enum { KEYWORD_RETURN(ENUM); } 233 234 __extension__ { KEYWORD_RETURN(EXTENSION); } // GCC 235 exception { KEYWORD_RETURN(EXCEPTION); } // CFA 234 236 extern { KEYWORD_RETURN(EXTERN); } 237 fallthrough { KEYWORD_RETURN(FALLTHROUGH); } // CFA 235 238 fallthru { KEYWORD_RETURN(FALLTHRU); } // CFA 236 fallthrough { KEYWORD_RETURN(FALLTHROUGH); } // CFA237 239 finally { KEYWORD_RETURN(FINALLY); } // CFA 238 240 float { KEYWORD_RETURN(FLOAT); } 241 _Float32 { KEYWORD_RETURN(FLOAT); } // GCC 242 _Float32x { KEYWORD_RETURN(FLOAT); } // GCC 243 _Float64 { KEYWORD_RETURN(DOUBLE); } // GCC 244 _Float64x { KEYWORD_RETURN(DOUBLE); } // GCC 239 245 __float80 { KEYWORD_RETURN(FLOAT80); } // GCC 240 246 float80 { KEYWORD_RETURN(FLOAT80); } // GCC 247 _Float128 { KEYWORD_RETURN(FLOAT128); } // GCC 248 _Float128x { KEYWORD_RETURN(FLOAT128); } // GCC 241 249 __float128 { KEYWORD_RETURN(FLOAT128); } // GCC 242 250 float128 { KEYWORD_RETURN(FLOAT128); } // GCC … … 264 272 __builtin_offsetof { KEYWORD_RETURN(OFFSETOF); } // GCC 265 273 one_t { NUMERIC_RETURN(ONE_T); } // CFA 274 or { QKEYWORD_RETURN(WOR); } // CFA 266 275 otype { KEYWORD_RETURN(OTYPE); } // CFA 267 276 register { KEYWORD_RETURN(REGISTER); } … … 300 309 __volatile__ { KEYWORD_RETURN(VOLATILE); } // GCC 301 310 waitfor { KEYWORD_RETURN(WAITFOR); } 302 or { QKEYWORD_RETURN(WOR); } // CFA303 311 when { KEYWORD_RETURN(WHEN); } 304 312 while { KEYWORD_RETURN(WHILE); } … … 308 316 /* identifier */ 309 317 {identifier} { IDENTIFIER_RETURN(); } 318 "`"{identifier}"`" { // CFA 319 yytext[yyleng - 1] = '\0'; yytext += 1; // SKULLDUGGERY: remove backquotes (ok to shorten?) 320 IDENTIFIER_RETURN(); 321 } 310 322 {attr_identifier} { ATTRIBUTE_RETURN(); } 311 "`" { BEGIN BKQUOTE; }312 <BKQUOTE>{identifier} { IDENTIFIER_RETURN(); }313 <BKQUOTE>"`" { BEGIN 0; }314 323 315 324 /* numeric constants */ 325 {binary_constant} { NUMERIC_RETURN(INTEGERconstant); } 326 {octal_constant} { NUMERIC_RETURN(INTEGERconstant); } 316 327 {decimal_constant} { NUMERIC_RETURN(INTEGERconstant); } 317 {octal_constant} { NUMERIC_RETURN(INTEGERconstant); }318 328 {hex_constant} { NUMERIC_RETURN(INTEGERconstant); } 319 329 {floating_decimal} { NUMERIC_RETURN(FLOATING_DECIMALconstant); } // must appear before floating_constant … … 325 335 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); } 326 336 <QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); } 327 <QUOTE>['\n] {user_suffix_opt}{ BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }337 <QUOTE>['\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); } 328 338 /* ' stop editor highlighting */ 329 339 … … 331 341 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); } 332 342 <STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); } 333 <STRING>["\n] {user_suffix_opt}{ BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }343 <STRING>["\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); } 334 344 /* " stop editor highlighting */ 335 345 … … 341 351 /* punctuation */ 342 352 "@" { ASCIIOP_RETURN(); } 353 "`" { ASCIIOP_RETURN(); } 343 354 "[" { ASCIIOP_RETURN(); } 344 355 "]" { ASCIIOP_RETURN(); } … … 399 410 ">>=" { NAMEDOP_RETURN(RSassign); } 400 411 412 "~=" { NAMEDOP_RETURN(Erange); } // CFA 401 413 "@=" { NAMEDOP_RETURN(ATassign); } // CFA 402 414 … … 405 417 "?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); } 406 418 "^?{}" { IDENTIFIER_RETURN(); } 407 "?`"{identifier} { IDENTIFIER_RETURN(); } // unitoperator419 "?`"{identifier} { IDENTIFIER_RETURN(); } // postfix operator 408 420 "?"{op_binary_over}"?" { IDENTIFIER_RETURN(); } // binary 409 421 /* … … 448 460 449 461 %% 462 450 463 // ----end of lexer---- 451 464 452 465 void yyerror( const char * errmsg ) { 453 cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1 454 << ": " << SemanticError::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl; 466 SemanticErrorThrow = true; 467 cerr << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1 468 << ": " << ErrorHelpers::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl; 455 469 } 456 470
Note:
See TracChangeset
for help on using the changeset viewer.