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