Changeset 937e51d for src/Parser/lex.ll
- Timestamp:
- Jun 26, 2015, 4:00:26 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 0df292b, e0ff3e6
- Parents:
- eb50842 (diff), 1869adf (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 moved
-
src/Parser/lex.ll (moved) (moved from src/Parser/lex.l ) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/lex.ll
reb50842 r937e51d 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Tue May 19 15:41:54 201513 * Update Count : 3 3112 * Last Modified On : Fri Jun 19 11:10:14 2015 13 * Update Count : 392 14 14 */ 15 15 16 16 %option yylineno 17 %option nounput 17 18 18 19 %{ 19 // This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive 20 // have been performed and removed from the source. The only exceptions are preprocessor directives passed to21 // the compiler (e.g.,line-number directives) and C/C++ style comments, which are ignored.20 // This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been 21 // performed and removed from the source. The only exceptions are preprocessor directives passed to the compiler (e.g., 22 // line-number directives) and C/C++ style comments, which are ignored. 22 23 23 24 //**************************** Includes and Defines **************************** … … 27 28 #include "lex.h" 28 29 #include "ParseNode.h" 29 #include " cfa.tab.h"// YACC generated definitions based on C++ grammar30 #include "parser.h" // YACC generated definitions based on C++ grammar 30 31 31 32 char *yyfilename; 32 33 std::string *strtext; // accumulate parts of character and string constant value 33 34 35 #define RETURN_LOCN(x) yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x ) 36 #define RETURN_VAL(x) yylval.tok.str = new std::string( yytext ); RETURN_LOCN( x ) 37 #define RETURN_CHAR(x) yylval.tok.str = NULL; RETURN_LOCN( x ) 38 #define RETURN_STR(x) yylval.tok.str = strtext; RETURN_LOCN( x ) 39 34 40 #define WHITE_RETURN(x) // do nothing 35 #define NEWLINE_RETURN() WHITE_RETURN('\n') 36 #define RETURN_VAL(x) yylval.tok.str = new std::string(yytext); \ 37 yylval.tok.loc.file = yyfilename; \ 38 yylval.tok.loc.line = yylineno; \ 39 return(x) 40 #define RETURN_STR(x) yylval.tok.str = strtext; \ 41 yylval.tok.loc.file = yyfilename; \ 42 yylval.tok.loc.line = yylineno; \ 43 return(x) 44 45 #define KEYWORD_RETURN(x) RETURN_VAL(x) // keyword 46 #define IDENTIFIER_RETURN() RETURN_VAL((typedefTable.isIdentifier(yytext) ? IDENTIFIER : typedefTable.isTypedef(yytext) ? TYPEDEFname : TYPEGENname)) 47 //#define ATTRIBUTE_RETURN() RETURN_VAL((typedefTable.isIdentifier(yytext) ? ATTR_IDENTIFIER : typedefTable.isTypedef(yytext) ? ATTR_TYPEDEFname : ATTR_TYPEGENname)) 48 #define ATTRIBUTE_RETURN() RETURN_VAL(ATTR_IDENTIFIER) 49 50 #define ASCIIOP_RETURN() RETURN_VAL((int)yytext[0]) // single character operator 51 #define NAMEDOP_RETURN(x) RETURN_VAL(x) // multichar operator, with a name 52 53 #define NUMERIC_RETURN(x) rm_underscore(); RETURN_VAL(x) // numeric constant 41 #define NEWLINE_RETURN() WHITE_RETURN( '\n' ) 42 #define ASCIIOP_RETURN() RETURN_CHAR( (int)yytext[0] ) // single character operator 43 #define NAMEDOP_RETURN(x) RETURN_VAL( x ) // multichar operator, with a name 44 #define NUMERIC_RETURN(x) rm_underscore(); RETURN_VAL( x ) // numeric constant 45 #define KEYWORD_RETURN(x) RETURN_CHAR( x ) // keyword 46 #define IDENTIFIER_RETURN() RETURN_VAL( (typedefTable.isIdentifier( yytext ) ? IDENTIFIER : typedefTable.isTypedef( yytext ) ? TYPEDEFname : TYPEGENname ) ) 47 #define ATTRIBUTE_RETURN() RETURN_VAL( ATTR_IDENTIFIER ) 54 48 55 49 void rm_underscore() { … … 114 108 hex_escape "\\""x""_"?{hex_digits} 115 109 escape_seq {simple_escape}|{octal_escape}|{hex_escape}|{universal_char} 110 cwide_prefix "L"|"U"|"u" 111 swide_prefix {cwide_prefix}|"u8" 116 112 117 113 // display/white-space characters … … 165 161 ^{h_white}*"#"[^\n]*"\n" ; 166 162 167 /* ignore C style comments */163 /* ignore C style comments (ALSO HANDLED BY CPP) */ 168 164 "/*" { BEGIN COMMENT; } 169 <COMMENT>.|\n ;170 <COMMENT>"*/" { BEGIN 0; }171 172 /* ignore C++ style comments */173 "//"[^\n]*"\n" ;165 <COMMENT>.|\n ; 166 <COMMENT>"*/" { BEGIN 0; } 167 168 /* ignore C++ style comments (ALSO HANDLED BY CPP) */ 169 "//"[^\n]*"\n" ; 174 170 175 171 /* ignore whitespace */ … … 275 271 "0" { NUMERIC_RETURN(ZERO); } // CFA 276 272 "1" { NUMERIC_RETURN(ONE); } // CFA 277 {decimal_constant} { NUMERIC_RETURN(INTEGERconstant); }278 {octal_constant} { NUMERIC_RETURN(INTEGERconstant); }279 {hex_constant} { NUMERIC_RETURN(INTEGERconstant); }273 {decimal_constant} { NUMERIC_RETURN(INTEGERconstant); } 274 {octal_constant} { NUMERIC_RETURN(INTEGERconstant); } 275 {hex_constant} { NUMERIC_RETURN(INTEGERconstant); } 280 276 {floating_constant} { NUMERIC_RETURN(FLOATINGconstant); } 281 277 {hex_floating_constant} { NUMERIC_RETURN(FLOATINGconstant); } 282 278 283 279 /* character constant, allows empty value */ 284 "L"?"_"?[']{ BEGIN QUOTE; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }280 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); } 285 281 <QUOTE>[^'\\\n]* { *strtext += std::string( yytext ); } 286 282 <QUOTE>['\n] { BEGIN 0; *strtext += std::string( yytext); RETURN_STR(CHARACTERconstant); } … … 288 284 289 285 /* string constant */ 290 "L"?"_"?["]{ BEGIN STRING; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }286 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); } 291 287 <STRING>[^"\\\n]* { *strtext += std::string( yytext ); } 292 <STRING>["\n] { BEGIN 0; *strtext += std::string( yytext ); RETURN_STR(STRINGliteral); }288 <STRING>["\n] { BEGIN 0; *strtext += std::string( yytext ); RETURN_STR(STRINGliteral); } 293 289 /* " stop highlighting */ 294 290 291 /* common character/string constant */ 295 292 <QUOTE,STRING>{escape_seq} { rm_underscore(); *strtext += std::string( yytext ); } 296 <QUOTE,STRING>[\\] { *strtext += std::string( yytext ); } // unknown escape character 293 <QUOTE,STRING>"\\"{h_white}*"\n" {} // continuation (ALSO HANDLED BY CPP) 294 <QUOTE,STRING>"\\" { *strtext += std::string( yytext ); } // unknown escape character 297 295 298 296 /* punctuation */ … … 355 353 /* CFA, operator identifier */ 356 354 {op_unary}"?" { IDENTIFIER_RETURN(); } // unary 357 "?"({op_unary_pre_post}|"()"|"[?]" ) { IDENTIFIER_RETURN(); }355 "?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); } 358 356 "?"{op_binary_over}"?" { IDENTIFIER_RETURN(); } // binary 359 357 /* … … 400 398 401 399 // Local Variables: // 402 // fill-column: 110//400 // mode: c++ // 403 401 // tab-width: 4 // 404 // mode: c++ //405 402 // compile-command: "make install" // 406 403 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.