Changeset 8c17ab0 for translator/Parser/lex.l
- Timestamp:
- Nov 13, 2014, 3:09:54 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:
- c8ffe20b
- Parents:
- 134b86a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/Parser/lex.l
r134b86a r8c17ab0 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sat Nov 1 18:09:47 200313 * Update Count : 19712 * Last Modified On : Tue Nov 11 08:10:05 2014 13 * Update Count : 215 14 14 */ 15 15 … … 17 17 18 18 %{ 19 / *This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor20 21 22 are ignored. */ 23 24 / *************** Includes and Defines *****************************/19 // This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor 20 // directive have been performed and removed from the source. The only exceptions are preprocessor 21 // directives passed to the compiler (e.g., line-number directives) and C/C++ style comments, which 22 // are ignored. 23 24 //**************************** Includes and Defines **************************** 25 25 26 26 #include <string> … … 28 28 #include "lex.h" 29 29 #include "ParseNode.h" 30 #include "cfa.tab.h" / * YACC generated definitions based on C++ grammar */30 #include "cfa.tab.h" // YACC generated definitions based on C++ grammar 31 31 32 32 char *yyfilename; 33 33 34 #define WHITE_RETURN(x) /* do nothing */34 #define WHITE_RETURN(x) // do nothing 35 35 #define NEWLINE_RETURN() WHITE_RETURN('\n') 36 36 #define RETURN_VAL(x) yylval.tok.str = new std::string(yytext); \ … … 39 39 return(x) 40 40 41 #define KEYWORD_RETURN(x) RETURN_VAL(x) / * keyword */41 #define KEYWORD_RETURN(x) RETURN_VAL(x) // keyword 42 42 #define IDENTIFIER_RETURN() RETURN_VAL((typedefTable.isIdentifier(yytext) ? IDENTIFIER : typedefTable.isTypedef(yytext) ? TYPEDEFname : TYPEGENname)) 43 #define ATTRIBUTE_RETURN() RETURN_VAL((typedefTable.isIdentifier(yytext) ? ATTR_IDENTIFIER : typedefTable.isTypedef(yytext) ? ATTR_TYPEDEFname : ATTR_TYPEGENname)) 44 45 #define ASCIIOP_RETURN() RETURN_VAL((int)yytext[0]) /* single character operator */ 46 #define NAMEDOP_RETURN(x) RETURN_VAL(x) /* multichar operator, with a name */ 47 48 #define NUMERIC_RETURN(x) rm_underscore(); RETURN_VAL(x) /* numeric constant */ 49 50 void rm_underscore() { /* remove underscores in constant or escape sequence */ 43 //#define ATTRIBUTE_RETURN() RETURN_VAL((typedefTable.isIdentifier(yytext) ? ATTR_IDENTIFIER : typedefTable.isTypedef(yytext) ? ATTR_TYPEDEFname : ATTR_TYPEGENname)) 44 #define ATTRIBUTE_RETURN() RETURN_VAL(ATTR_IDENTIFIER) 45 46 #define ASCIIOP_RETURN() RETURN_VAL((int)yytext[0]) // single character operator 47 #define NAMEDOP_RETURN(x) RETURN_VAL(x) // multichar operator, with a name 48 49 #define NUMERIC_RETURN(x) rm_underscore(); RETURN_VAL(x) // numeric constant 50 51 void rm_underscore() { // remove underscores in constant or escape sequence 51 52 int j = 0; 52 53 for ( int i = 0; i < yyleng; i += 1 ) { … … 68 69 universal_char "\\"((u{hex_quad})|(U{hex_quad}{2})) 69 70 70 / * identifier, GCC: $ in identifier */71 // identifier, GCC: $ in identifier 71 72 identifier ([a-zA-Z_$]|{universal_char})([0-9a-zA-Z_$]|{universal_char})* 72 73 73 /* attribute identifier, GCC: $ in identifier */ 74 // quoted identifier 75 quoted_identifier "`"{identifier}"`" 76 77 // attribute identifier, GCC: $ in identifier 74 78 attr_identifier "@"{identifier} 75 79 76 / * numeric constants, CFA: '_' in constant */80 // numeric constants, CFA: '_' in constant 77 81 hex_quad {hex}{4} 78 82 integer_suffix "_"?(([uU][lL]?)|([uU]("ll"|"LL")?)|([lL][uU]?)|("ll"|"LL")[uU]?) … … 99 103 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix}? 100 104 101 / * character escape sequence, GCC: \e => esc character */105 // character escape sequence, GCC: \e => esc character 102 106 simple_escape "\\"[abefnrtv'"?\\] 107 // ' stop highlighting 103 108 octal_escape "\\"{octal}{1,3} 104 109 hex_escape "\\""x"{hex}+ 105 110 escape_seq {simple_escape}|{octal_escape}|{hex_escape}|{universal_char} 106 111 107 / * display/white-space characters */112 // display/white-space characters 108 113 h_tab [\011] 109 114 form_feed [\014] … … 112 117 h_white [ ]|{h_tab} 113 118 114 / * operators */119 // operators 115 120 op_unary_only "~"|"!" 116 121 op_unary_binary "+"|"-"|"*" … … 124 129 125 130 %x COMMENT 131 %x QUOTED 126 132 127 133 %% 128 134 /* line directives */ 129 135 ^{h_white}*"#"{h_white}*[0-9]+{h_white}*["][^"\n]+["][^\n]*"\n" { 136 /* " stop highlighting */ 130 137 char *end_num; 131 138 char *begin_string, *end_string; … … 178 185 catch {KEYWORD_RETURN(CATCH);} /* CFA */ 179 186 char {KEYWORD_RETURN(CHAR);} 180 choose {KEYWORD_RETURN(CHOOSE);} 187 choose {KEYWORD_RETURN(CHOOSE);} /* CFA */ 181 188 _Complex {KEYWORD_RETURN(COMPLEX);} /* ANSI99 */ 182 189 __complex {KEYWORD_RETURN(COMPLEX);} /* GCC */ … … 185 192 __const {KEYWORD_RETURN(CONST);} /* GCC */ 186 193 __const__ {KEYWORD_RETURN(CONST);} /* GCC */ 187 context {KEYWORD_RETURN(CONTEXT);} 194 context {KEYWORD_RETURN(CONTEXT);} /* CFA */ 188 195 continue {KEYWORD_RETURN(CONTINUE);} 189 196 default {KEYWORD_RETURN(DEFAULT);} 190 197 do {KEYWORD_RETURN(DO);} 191 198 double {KEYWORD_RETURN(DOUBLE);} 192 dtype {KEYWORD_RETURN(DTYPE);} 199 dtype {KEYWORD_RETURN(DTYPE);} /* CFA */ 193 200 else {KEYWORD_RETURN(ELSE);} 194 201 enum {KEYWORD_RETURN(ENUM);} 195 202 __extension__ {KEYWORD_RETURN(EXTENSION);} /* GCC */ 196 203 extern {KEYWORD_RETURN(EXTERN);} 197 fallthru {KEYWORD_RETURN(FALLTHRU);} 204 fallthru {KEYWORD_RETURN(FALLTHRU);} /* CFA */ 198 205 finally {KEYWORD_RETURN(FINALLY);} /* CFA */ 199 206 float {KEYWORD_RETURN(FLOAT);} 200 207 for {KEYWORD_RETURN(FOR);} 201 forall {KEYWORD_RETURN(FORALL);} 208 forall {KEYWORD_RETURN(FORALL);} /* CFA */ 202 209 fortran {KEYWORD_RETURN(FORTRAN);} 203 ftype {KEYWORD_RETURN(FTYPE);} 210 ftype {KEYWORD_RETURN(FTYPE);} /* CFA */ 204 211 goto {KEYWORD_RETURN(GOTO);} 205 212 if {KEYWORD_RETURN(IF);} … … 213 220 __label__ {KEYWORD_RETURN(LABEL);} /* GCC */ 214 221 long {KEYWORD_RETURN(LONG);} 215 lvalue {KEYWORD_RETURN(LVALUE);} 222 lvalue {KEYWORD_RETURN(LVALUE);} /* CFA */ 216 223 register {KEYWORD_RETURN(REGISTER);} 217 224 restrict {KEYWORD_RETURN(RESTRICT);} /* ANSI99 */ … … 229 236 throw {KEYWORD_RETURN(THROW);} /* CFA */ 230 237 try {KEYWORD_RETURN(TRY);} /* CFA */ 231 type {KEYWORD_RETURN(TYPE);} 238 type {KEYWORD_RETURN(TYPE);} /* CFA */ 232 239 typedef {KEYWORD_RETURN(TYPEDEF);} 233 240 typeof {KEYWORD_RETURN(TYPEOF);} /* GCC */ … … 245 252 {identifier} {IDENTIFIER_RETURN();} 246 253 {attr_identifier} {ATTRIBUTE_RETURN();} 254 "`" {BEGIN QUOTED;} 255 <QUOTED>{identifier} {IDENTIFIER_RETURN();} 256 <QUOTED>"`" {BEGIN 0;} 247 257 248 258 /* numeric constants */ … … 257 267 /* character constant, allows empty value */ 258 268 "L"?[']([^'\\\n]|{escape_seq})*['] {RETURN_VAL(CHARACTERconstant);} 269 /* ' stop highlighting */ 259 270 260 271 /* string constant */ 261 272 "L"?["]([^"\\\n]|{escape_seq})*["] {RETURN_VAL(STRINGliteral);} 273 /* " stop highlighting */ 262 274 263 275 /* punctuation */ … … 367 379 368 380 369 / * Local Variables: */370 / * fill-column: 100 */371 / * compile-command: "gmake" */372 / * End: */381 // Local Variables: 382 // fill-column: 100 383 // compile-command: "make" 384 // End:
Note: See TracChangeset
for help on using the changeset viewer.