Changeset 9ed4f94 for src/Parser/lex.ll
- Timestamp:
- Aug 30, 2017, 8:08:01 AM (6 years ago)
- Branches:
- aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- e5fccf4
- Parents:
- fc1ef62
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/lex.ll
rfc1ef62 r9ed4f94 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Tue Aug 22 22:43:39201713 * Update Count : 5 5812 * Last Modified On : Wed Aug 30 07:53:24 2017 13 * Update Count : 583 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 … … 154 158 memcpy( &filename, begin_string + 1, length ); // copy file name from yytext 155 159 filename[ length ] = '\0'; // terminate string with sentinel 156 // std::cout << "file " << filename << " line " << lineno << std::endl;160 //cout << "file " << filename << " line " << lineno << endl; 157 161 yylineno = lineno; 158 162 yyfilename = filename; … … 302 306 303 307 /* character constant, allows empty value */ 304 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }308 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); } 305 309 <QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); } 306 310 <QUOTE>['\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); } … … 308 312 309 313 /* string constant */ 310 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }314 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); } 311 315 <STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); } 312 316 <STRING>["\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); } … … 422 426 } 423 427 424 /* unknown character s*/425 . { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }428 /* unknown character */ 429 . { yyerror( "unknown character" ); } 426 430 427 431 %% 432 // ----end of lexer---- 433 434 void yyerror( const char * errmsg ) { 435 cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1 436 << ':' << SemanticError::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl; 437 } 428 438 429 439 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.