Changeset 937e51d for src/Parser/lex.ll


Ignore:
Timestamp:
Jun 26, 2015, 4:00:26 PM (10 years ago)
Author:
Aaron Moss <a3moss@…>
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.
Message:

Merge pointer to pointer to qualified fix into master

File:
1 moved

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    reb50842 r937e51d  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Tue May 19 15:41:54 2015
    13  * Update Count     : 331
     12 * Last Modified On : Fri Jun 19 11:10:14 2015
     13 * Update Count     : 392
    1414 */
    1515
    1616%option yylineno
     17%option nounput
    1718
    1819%{
    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 to
    21 // 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.
    2223
    2324//**************************** Includes and Defines ****************************
     
    2728#include "lex.h"
    2829#include "ParseNode.h"
    29 #include "cfa.tab.h"                                                                    // YACC generated definitions based on C++ grammar
     30#include "parser.h"                                                                             // YACC generated definitions based on C++ grammar
    3031
    3132char *yyfilename;
    3233std::string *strtext;                                                                   // accumulate parts of character and string constant value
    3334
     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
    3440#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 )
    5448
    5549void rm_underscore() {
     
    114108hex_escape "\\""x""_"?{hex_digits}
    115109escape_seq {simple_escape}|{octal_escape}|{hex_escape}|{universal_char}
     110cwide_prefix "L"|"U"|"u"
     111swide_prefix {cwide_prefix}|"u8"
    116112
    117113                                // display/white-space characters
     
    165161^{h_white}*"#"[^\n]*"\n" ;
    166162
    167                                 /* ignore C style comments */
     163                                /* ignore C style comments (ALSO HANDLED BY CPP) */
    168164"/*"                    { 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"  ;
    174170
    175171                                /* ignore whitespace */
     
    275271"0"                             { NUMERIC_RETURN(ZERO); }                               // CFA
    276272"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); }
    280276{floating_constant}     { NUMERIC_RETURN(FLOATINGconstant); }
    281277{hex_floating_constant} { NUMERIC_RETURN(FLOATINGconstant); }
    282278
    283279                                /* 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 ); }
    285281<QUOTE>[^'\\\n]* { *strtext += std::string( yytext ); }
    286282<QUOTE>['\n]    { BEGIN 0; *strtext += std::string( yytext); RETURN_STR(CHARACTERconstant); }
     
    288284
    289285                                /* 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 ); }
    291287<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); }
    293289                                /* " stop highlighting */
    294290
     291                                /* common character/string constant */
    295292<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
    297295
    298296                                /* punctuation */
     
    355353                                /* CFA, operator identifier */
    356354{op_unary}"?"   { IDENTIFIER_RETURN(); }                                // unary
    357 "?"({op_unary_pre_post}|"()"|"[?]") { IDENTIFIER_RETURN(); }
     355"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
    358356"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    359357        /*
     
    400398
    401399// Local Variables: //
    402 // fill-column: 110 //
     400// mode: c++ //
    403401// tab-width: 4 //
    404 // mode: c++ //
    405402// compile-command: "make install" //
    406403// End: //
Note: See TracChangeset for help on using the changeset viewer.