Ignore:
Timestamp:
Nov 13, 2014, 3:09:54 PM (10 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

add quoted identifiers, add compilation include directory, reformatted some files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/Parser/lex.l

    r134b86a r8c17ab0  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Sat Nov  1 18:09:47 2003
    13  * Update Count     : 197
     12 * Last Modified On : Tue Nov 11 08:10:05 2014
     13 * Update Count     : 215
    1414 */
    1515
     
    1717
    1818%{
    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 *****************************/
     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 ****************************
    2525
    2626#include <string>
     
    2828#include "lex.h"
    2929#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
    3131
    3232char *yyfilename;
    3333
    34 #define WHITE_RETURN(x)         /* do nothing */
     34#define WHITE_RETURN(x)                                 // do nothing
    3535#define NEWLINE_RETURN()        WHITE_RETURN('\n')
    3636#define RETURN_VAL(x)           yylval.tok.str = new std::string(yytext); \
     
    3939                                return(x)
    4040
    41 #define KEYWORD_RETURN(x)       RETURN_VAL(x)           /* keyword */
     41#define KEYWORD_RETURN(x)       RETURN_VAL(x)           // keyword
    4242#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
     51void rm_underscore() {                                  // remove underscores in constant or escape sequence
    5152    int j = 0;
    5253    for ( int i = 0; i < yyleng; i += 1 ) {
     
    6869universal_char "\\"((u{hex_quad})|(U{hex_quad}{2}))
    6970
    70         /* identifier, GCC: $ in identifier */
     71        // identifier, GCC: $ in identifier
    7172identifier ([a-zA-Z_$]|{universal_char})([0-9a-zA-Z_$]|{universal_char})*
    7273
    73         /* attribute identifier, GCC: $ in identifier */
     74        // quoted identifier
     75quoted_identifier "`"{identifier}"`"
     76
     77        // attribute identifier, GCC: $ in identifier
    7478attr_identifier "@"{identifier}
    7579
    76         /*  numeric constants, CFA: '_' in constant */
     80        // numeric constants, CFA: '_' in constant
    7781hex_quad {hex}{4}
    7882integer_suffix "_"?(([uU][lL]?)|([uU]("ll"|"LL")?)|([lL][uU]?)|("ll"|"LL")[uU]?)
     
    99103hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix}?
    100104
    101         /* character escape sequence, GCC: \e => esc character */
     105        // character escape sequence, GCC: \e => esc character
    102106simple_escape "\\"[abefnrtv'"?\\]
     107        // ' stop highlighting
    103108octal_escape "\\"{octal}{1,3}
    104109hex_escape "\\""x"{hex}+
    105110escape_seq {simple_escape}|{octal_escape}|{hex_escape}|{universal_char}
    106111
    107         /* display/white-space characters */
     112        // display/white-space characters
    108113h_tab [\011]
    109114form_feed [\014]
     
    112117h_white [ ]|{h_tab}
    113118
    114         /* operators */
     119        // operators
    115120op_unary_only "~"|"!"
    116121op_unary_binary "+"|"-"|"*"
     
    124129
    125130%x COMMENT
     131%x QUOTED
    126132
    127133%%
    128134        /* line directives */
    129135^{h_white}*"#"{h_white}*[0-9]+{h_white}*["][^"\n]+["][^\n]*"\n" {
     136        /* " stop highlighting */
    130137        char *end_num;
    131138        char *begin_string, *end_string;
     
    178185catch                   {KEYWORD_RETURN(CATCH);}        /* CFA */
    179186char                    {KEYWORD_RETURN(CHAR);}
    180 choose                  {KEYWORD_RETURN(CHOOSE);}
     187choose                  {KEYWORD_RETURN(CHOOSE);}       /* CFA */
    181188_Complex                {KEYWORD_RETURN(COMPLEX);}      /* ANSI99 */
    182189__complex               {KEYWORD_RETURN(COMPLEX);}      /* GCC */
     
    185192__const                 {KEYWORD_RETURN(CONST);}        /* GCC */
    186193__const__               {KEYWORD_RETURN(CONST);}        /* GCC */
    187 context                 {KEYWORD_RETURN(CONTEXT);}
     194context                 {KEYWORD_RETURN(CONTEXT);}      /* CFA */
    188195continue                {KEYWORD_RETURN(CONTINUE);}
    189196default                 {KEYWORD_RETURN(DEFAULT);}
    190197do                      {KEYWORD_RETURN(DO);}
    191198double                  {KEYWORD_RETURN(DOUBLE);}
    192 dtype                   {KEYWORD_RETURN(DTYPE);}
     199dtype                   {KEYWORD_RETURN(DTYPE);}        /* CFA */
    193200else                    {KEYWORD_RETURN(ELSE);}
    194201enum                    {KEYWORD_RETURN(ENUM);}
    195202__extension__           {KEYWORD_RETURN(EXTENSION);}    /* GCC */
    196203extern                  {KEYWORD_RETURN(EXTERN);}
    197 fallthru                {KEYWORD_RETURN(FALLTHRU);}
     204fallthru                {KEYWORD_RETURN(FALLTHRU);}     /* CFA */
    198205finally                 {KEYWORD_RETURN(FINALLY);}      /* CFA */
    199206float                   {KEYWORD_RETURN(FLOAT);}
    200207for                     {KEYWORD_RETURN(FOR);}
    201 forall                  {KEYWORD_RETURN(FORALL);}
     208forall                  {KEYWORD_RETURN(FORALL);}       /* CFA */
    202209fortran                 {KEYWORD_RETURN(FORTRAN);}
    203 ftype                   {KEYWORD_RETURN(FTYPE);}
     210ftype                   {KEYWORD_RETURN(FTYPE);}        /* CFA */
    204211goto                    {KEYWORD_RETURN(GOTO);}
    205212if                      {KEYWORD_RETURN(IF);}
     
    213220__label__               {KEYWORD_RETURN(LABEL);}        /* GCC */
    214221long                    {KEYWORD_RETURN(LONG);}
    215 lvalue                  {KEYWORD_RETURN(LVALUE);}
     222lvalue                  {KEYWORD_RETURN(LVALUE);}       /* CFA */
    216223register                {KEYWORD_RETURN(REGISTER);}
    217224restrict                {KEYWORD_RETURN(RESTRICT);}     /* ANSI99 */
     
    229236throw                   {KEYWORD_RETURN(THROW);}        /* CFA */
    230237try                     {KEYWORD_RETURN(TRY);}          /* CFA */
    231 type                    {KEYWORD_RETURN(TYPE);}
     238type                    {KEYWORD_RETURN(TYPE);}         /* CFA */
    232239typedef                 {KEYWORD_RETURN(TYPEDEF);}
    233240typeof                  {KEYWORD_RETURN(TYPEOF);}       /* GCC */
     
    245252{identifier}            {IDENTIFIER_RETURN();}
    246253{attr_identifier}       {ATTRIBUTE_RETURN();}
     254"`"                     {BEGIN QUOTED;}
     255<QUOTED>{identifier}    {IDENTIFIER_RETURN();}
     256<QUOTED>"`"             {BEGIN 0;}
    247257
    248258        /* numeric constants */
     
    257267        /* character constant, allows empty value */
    258268"L"?[']([^'\\\n]|{escape_seq})*['] {RETURN_VAL(CHARACTERconstant);}
     269        /* ' stop highlighting */
    259270
    260271        /* string constant */
    261272"L"?["]([^"\\\n]|{escape_seq})*["] {RETURN_VAL(STRINGliteral);}
     273        /* " stop highlighting */
    262274
    263275        /* punctuation */
     
    367379
    368380
    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.