Changes in src/Parser/lex.ll [5b2edbc:76c62b2]
- File:
-
- 1 edited
-
src/Parser/lex.ll (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/lex.ll
r5b2edbc r76c62b2 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : T ue Aug 22 22:43:39201713 * Update Count : 5 5812 * Last Modified On : Thu Aug 31 21:30:10 2017 13 * Update Count : 598 14 14 */ 15 15 … … 19 19 20 20 %{ 21 // Th islexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been21 // The lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been 22 22 // performed and removed from the source. The only exceptions are preprocessor directives passed to the compiler (e.g., 23 23 // line-number directives) and C/C++ style comments, which are ignored. … … 25 25 //**************************** Includes and Defines **************************** 26 26 27 unsigned int column = 0; // position of the end of the last token parsed 28 #define YY_USER_ACTION column += yyleng; // trigger before each matching rule's action 29 27 30 #include <string> 28 31 #include <cstdio> // FILENAME_MAX 32 using namespace std; 29 33 30 34 #include "ParseNode.h" … … 32 36 33 37 char *yyfilename; 34 st d::string *strtext;// accumulate parts of character and string constant value38 string *strtext; // accumulate parts of character and string constant value 35 39 36 40 #define RETURN_LOCN(x) yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x ) 37 #define RETURN_VAL(x) yylval.tok.str = new st d::string( yytext ); RETURN_LOCN( x )41 #define RETURN_VAL(x) yylval.tok.str = new string( yytext ); RETURN_LOCN( x ) 38 42 #define RETURN_CHAR(x) yylval.tok.str = nullptr; RETURN_LOCN( x ) 39 43 #define RETURN_STR(x) yylval.tok.str = strtext; RETURN_LOCN( x ) 40 44 41 45 #define WHITE_RETURN(x) // do nothing 42 #define NEWLINE_RETURN() WHITE_RETURN( '\n' )46 #define NEWLINE_RETURN() column = 0; WHITE_RETURN( '\n' ) 43 47 #define ASCIIOP_RETURN() RETURN_CHAR( (int)yytext[0] ) // single character operator 44 48 #define NAMEDOP_RETURN(x) RETURN_CHAR( x ) // multichar operator, with a name … … 53 57 yyleng = 0; 54 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 55 67 if ( yytext[i] != '_' ) { 56 68 yytext[yyleng] = yytext[i]; … … 77 89 attr_identifier "@"{identifier} 78 90 91 user_suffix_opt ("`"{identifier})? 92 79 93 // numeric constants, CFA: '_' in constant 80 94 hex_quad {hex}("_"?{hex}){3} 81 integer_suffix "_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?)))95 integer_suffix_opt ("_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?))))? 82 96 83 97 octal_digits ({octal})|({octal}({octal}|"_")*{octal}) 84 98 octal_prefix "0""_"? 85 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix }?99 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt}{user_suffix_opt} 86 100 87 101 nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal}) 88 decimal_constant {nonzero_digits}{integer_suffix }?102 decimal_constant {nonzero_digits}{integer_suffix_opt}{user_suffix_opt} 89 103 90 104 hex_digits ({hex})|({hex}({hex}|"_")*{hex}) 91 105 hex_prefix "0"[xX]"_"? 92 hex_constant {hex_prefix}{hex_digits}{integer_suffix}? 93 106 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt}{user_suffix_opt} 107 108 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 109 floating_suffix_opt ("_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL"))? 94 110 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 95 real_decimal {decimal_digits}"."{exponent}?{floating_suffix }?96 real_fraction "."{decimal_digits}{exponent}?{floating_suffix }?111 real_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt}{user_suffix_opt} 112 real_fraction "."{decimal_digits}{exponent}?{floating_suffix_opt}{user_suffix_opt} 97 113 real_constant {decimal_digits}{real_fraction} 98 114 exponent "_"?[eE]"_"?[+-]?{decimal_digits} 99 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 100 floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL") 101 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}? 115 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix_opt}{user_suffix_opt} 102 116 103 117 binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits} 104 118 hex_fractional_constant ({hex_digits}?"."{hex_digits})|({hex_digits}".") 105 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix }?119 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix_opt} 106 120 107 121 // character escape sequence, GCC: \e => esc character … … 154 168 memcpy( &filename, begin_string + 1, length ); // copy file name from yytext 155 169 filename[ length ] = '\0'; // terminate string with sentinel 156 // std::cout << "file " << filename << " line " << lineno << std::endl;170 //cout << "file " << filename << " line " << lineno << endl; 157 171 yylineno = lineno; 158 172 yyfilename = filename; … … 237 251 __label__ { KEYWORD_RETURN(LABEL); } // GCC 238 252 long { KEYWORD_RETURN(LONG); } 239 lvalue { KEYWORD_RETURN(LVALUE); } // CFA240 253 monitor { KEYWORD_RETURN(MONITOR); } // CFA 241 254 mutex { KEYWORD_RETURN(MUTEX); } // CFA … … 303 316 304 317 /* character constant, allows empty value */ 305 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }318 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); } 306 319 <QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); } 307 <QUOTE>['\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }320 <QUOTE>['\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); } 308 321 /* ' stop highlighting */ 309 322 310 323 /* string constant */ 311 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }324 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); } 312 325 <STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); } 313 <STRING>["\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }326 <STRING>["\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); } 314 327 /* " stop highlighting */ 315 328 … … 384 397 {op_unary}"?" { IDENTIFIER_RETURN(); } // unary 385 398 "?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); } 386 "^?{}" { IDENTIFIER_RETURN(); } 399 "^?{}" { IDENTIFIER_RETURN(); } 400 "?`"{identifier} { IDENTIFIER_RETURN(); } // unit operator 387 401 "?"{op_binary_over}"?" { IDENTIFIER_RETURN(); } // binary 388 402 /* … … 423 437 } 424 438 425 /* unknown character s*/426 . { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }439 /* unknown character */ 440 . { yyerror( "unknown character" ); } 427 441 428 442 %% 443 // ----end of lexer---- 444 445 void yyerror( const char * errmsg ) { 446 cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1 447 << ": " << SemanticError::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl; 448 } 429 449 430 450 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.