Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    rad28abb r5b2edbc  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Aug 30 17:35:21 2017
    13  * Update Count     : 584
     12 * Last Modified On : Tue Aug 22 22:43:39 2017
     13 * Update Count     : 558
    1414 */
    1515
     
    1919
    2020%{
    21 // The lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been
     21// This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been
    2222// performed and removed from the source. The only exceptions are preprocessor directives passed to the compiler (e.g.,
    2323// line-number directives) and C/C++ style comments, which are ignored.
     
    2525//**************************** Includes and Defines ****************************
    2626
    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 
    3027#include <string>
    3128#include <cstdio>                                                                               // FILENAME_MAX
    32 using namespace std;
    3329
    3430#include "ParseNode.h"
     
    3632
    3733char *yyfilename;
    38 string *strtext;                                                                                // accumulate parts of character and string constant value
     34std::string *strtext;                                                                   // accumulate parts of character and string constant value
    3935
    4036#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 string( yytext ); RETURN_LOCN( x )
     37#define RETURN_VAL(x)           yylval.tok.str = new std::string( yytext ); RETURN_LOCN( x )
    4238#define RETURN_CHAR(x)          yylval.tok.str = nullptr; RETURN_LOCN( x )
    4339#define RETURN_STR(x)           yylval.tok.str = strtext; RETURN_LOCN( x )
    4440
    4541#define WHITE_RETURN(x)         // do nothing
    46 #define NEWLINE_RETURN()        column = 0; WHITE_RETURN( '\n' )
     42#define NEWLINE_RETURN()        WHITE_RETURN( '\n' )
    4743#define ASCIIOP_RETURN()        RETURN_CHAR( (int)yytext[0] ) // single character operator
    4844#define NAMEDOP_RETURN(x)       RETURN_CHAR( x )                        // multichar operator, with a name
     
    158154                memcpy( &filename, begin_string + 1, length );  // copy file name from yytext
    159155                filename[ length ] = '\0';                                              // terminate string with sentinel
    160                 //cout << "file " << filename << " line " << lineno << endl;
     156                //std::cout << "file " << filename << " line " << lineno << std::endl;
    161157                yylineno = lineno;
    162158                yyfilename = filename;
     
    241237__label__               { KEYWORD_RETURN(LABEL); }                              // GCC
    242238long                    { KEYWORD_RETURN(LONG); }
     239lvalue                  { KEYWORD_RETURN(LVALUE); }                             // CFA
    243240monitor                 { KEYWORD_RETURN(MONITOR); }                    // CFA
    244241mutex                   { KEYWORD_RETURN(MUTEX); }                              // CFA
     
    306303
    307304                                /* character constant, allows empty value */
    308 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); }
     305({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
    309306<QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); }
    310307<QUOTE>['\n]    { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
     
    312309
    313310                                /* string constant */
    314 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); }
     311({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
    315312<STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); }
    316313<STRING>["\n]   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
     
    426423}
    427424
    428                                 /* unknown character */
    429 .                               { yyerror( "unknown character" ); }
     425                                /* unknown characters */
     426.                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
    430427
    431428%%
    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 }
    438429
    439430// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.