Changeset 90152a4 for src/Parser/lex.ll


Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (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 branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    rf9feab8 r90152a4  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Oct 25 13:53:56 2017
    13  * Update Count     : 634
     12 * Last Modified On : Wed Aug  8 17:23:17 2018
     13 * Update Count     : 685
    1414 */
    1515
     
    2525//**************************** Includes and Defines ****************************
    2626
     27// trigger before each matching rule's action
     28#define YY_USER_ACTION \
     29        yylloc.first_line = yylineno; \
     30        yylloc.first_column = column; \
     31        column += yyleng; \
     32        yylloc.last_column = column; \
     33        yylloc.last_line = yylineno; \
     34        yylloc.filename = yyfilename ? yyfilename : "";
    2735unsigned int column = 0;                                                                // position of the end of the last token parsed
    28 #define YY_USER_ACTION yylloc.first_line = yylineno; yylloc.first_column = column; column += yyleng; yylloc.last_column = column; yylloc.last_line = yylineno; yylloc.filename = yyfilename ? yyfilename : "";                          // trigger before each matching rule's action
    2936
    3037#include <string>
     
    4956#define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL( x ) // numeric constant
    5057#define KEYWORD_RETURN(x)       RETURN_CHAR( x )                        // keyword
    51 #define QKEYWORD_RETURN(x)      typedefTable.isKind( yytext ); RETURN_VAL(x); // quasi-keyword
     58#define QKEYWORD_RETURN(x)      RETURN_VAL(x);                          // quasi-keyword
    5259#define IDENTIFIER_RETURN()     RETURN_VAL( typedefTable.isKind( yytext ) )
    5360#define ATTRIBUTE_RETURN()      RETURN_VAL( ATTR_IDENTIFIER )
    5461
    5562void rm_underscore() {
    56         // Remove underscores in numeric constant by copying the non-underscore characters to the front of the string.
     63        // SKULLDUGGERY: remove underscores (ok to shorten?)
    5764        yyleng = 0;
    58         for ( int i = 0; yytext[i] != '\0'; i += 1 ) {
    59                 if ( yytext[i] == '`' ) {
    60                         // copy user suffix
    61                         for ( ; yytext[i] != '\0'; i += 1 ) {
    62                                 yytext[yyleng] = yytext[i];
    63                                 yyleng += 1;
    64                         } // for
    65                         break;
    66                 } // if
     65        for ( int i = 0; yytext[i] != '\0'; i += 1 ) {          // copying non-underscore characters to front of string
    6766                if ( yytext[i] != '_' ) {
    6867                        yytext[yyleng] = yytext[i];
     
    7170        } // for
    7271        yytext[yyleng] = '\0';
    73 }
     72} // rm_underscore
    7473
    7574// Stop warning due to incorrectly generated flex code.
     
    7776%}
    7877
     78binary [0-1]
    7979octal [0-7]
    8080nonzero [1-9]
     
    8989attr_identifier "@"{identifier}
    9090
    91 user_suffix_opt ("`"{identifier})?
    92 
    9391                                // numeric constants, CFA: '_' in constant
    9492hex_quad {hex}("_"?{hex}){3}
    9593size_opt (8|16|32|64|128)?
    9694length ("ll"|"LL"|[lL]{size_opt})|("hh"|"HH"|[hH])
    97 integer_suffix_opt ("_"?(([uU]({length}?[iI]?)|([iI]{length}))|([iI]({length}?[uU]?)|([uU]{length}))|({length}([iI]?[uU]?)|([uU][iI]))|[zZ]))?{user_suffix_opt}
     95integer_suffix_opt ("_"?(([uU]({length}?[iI]?)|([iI]{length}))|([iI]({length}?[uU]?)|([uU]{length}))|({length}([iI]?[uU]?)|([uU][iI]))|[zZ]))?
    9896
    9997octal_digits ({octal})|({octal}({octal}|"_")*{octal})
     
    103101nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal})
    104102decimal_constant {nonzero_digits}{integer_suffix_opt}
     103
     104binary_digits ({binary})|({binary}({binary}|"_")*{binary})
     105binary_prefix "0"[bB]"_"?
     106binary_constant {binary_prefix}{binary_digits}{integer_suffix_opt}
    105107
    106108hex_digits ({hex})|({hex}({hex}|"_")*{hex})
     
    113115floating_length ([fFdDlL]|[lL]{floating_size})
    114116floating_suffix ({floating_length}?[iI]?)|([iI]{floating_length})
    115 floating_suffix_opt ("_"?({floating_suffix}|"DL"))?{user_suffix_opt}
     117floating_suffix_opt ("_"?({floating_suffix}|"DL"))?
    116118decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal})
    117119floating_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt}
     
    120122
    121123binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits}
    122 hex_floating_suffix_opt ("_"?({floating_suffix}))?{user_suffix_opt}
     124hex_floating_suffix_opt ("_"?({floating_suffix}))?
    123125hex_floating_fraction ({hex_digits}?"."{hex_digits})|({hex_digits}".")
    124126hex_floating_constant {hex_prefix}(({hex_floating_fraction}{binary_exponent})|({hex_digits}{binary_exponent})){hex_floating_suffix_opt}
     
    179181}
    180182
    181                                 /* ignore preprocessor directives (for now) */
    182 ^{h_white}*"#"[^\n]*"\n" ;
     183                                /* preprocessor-style directives */
     184^{h_white}*"#"[^\n]*"\n" { RETURN_VAL( DIRECTIVE ); }
    183185
    184186                                /* ignore C style comments (ALSO HANDLED BY CPP) */
     
    203205__asm                   { KEYWORD_RETURN(ASM); }                                // GCC
    204206__asm__                 { KEYWORD_RETURN(ASM); }                                // GCC
    205 _At                             { KEYWORD_RETURN(AT); }                                 // CFA
    206207_Atomic                 { KEYWORD_RETURN(ATOMIC); }                             // C11
    207208__attribute             { KEYWORD_RETURN(ATTRIBUTE); }                  // GCC
     
    232233enum                    { KEYWORD_RETURN(ENUM); }
    233234__extension__   { KEYWORD_RETURN(EXTENSION); }                  // GCC
     235exception               { KEYWORD_RETURN(EXCEPTION); }                  // CFA
    234236extern                  { KEYWORD_RETURN(EXTERN); }
     237fallthrough             { KEYWORD_RETURN(FALLTHROUGH); }                // CFA
    235238fallthru                { KEYWORD_RETURN(FALLTHRU); }                   // CFA
    236 fallthrough             { KEYWORD_RETURN(FALLTHROUGH); }                // CFA
    237239finally                 { KEYWORD_RETURN(FINALLY); }                    // CFA
    238240float                   { KEYWORD_RETURN(FLOAT); }
     241_Float32                { KEYWORD_RETURN(FLOAT); }                              // GCC
     242_Float32x               { KEYWORD_RETURN(FLOAT); }                              // GCC
     243_Float64                { KEYWORD_RETURN(DOUBLE); }                             // GCC
     244_Float64x               { KEYWORD_RETURN(DOUBLE); }                             // GCC
    239245__float80               { KEYWORD_RETURN(FLOAT80); }                    // GCC
    240246float80                 { KEYWORD_RETURN(FLOAT80); }                    // GCC
     247_Float128               { KEYWORD_RETURN(FLOAT128); }                   // GCC
     248_Float128x              { KEYWORD_RETURN(FLOAT128); }                   // GCC
    241249__float128              { KEYWORD_RETURN(FLOAT128); }                   // GCC
    242250float128                { KEYWORD_RETURN(FLOAT128); }                   // GCC
     
    264272__builtin_offsetof { KEYWORD_RETURN(OFFSETOF); }                // GCC
    265273one_t                   { NUMERIC_RETURN(ONE_T); }                              // CFA
     274or                              { QKEYWORD_RETURN(WOR); }                               // CFA
    266275otype                   { KEYWORD_RETURN(OTYPE); }                              // CFA
    267276register                { KEYWORD_RETURN(REGISTER); }
     
    300309__volatile__    { KEYWORD_RETURN(VOLATILE); }                   // GCC
    301310waitfor                 { KEYWORD_RETURN(WAITFOR); }
    302 or                              { QKEYWORD_RETURN(WOR); }                               // CFA
    303311when                    { KEYWORD_RETURN(WHEN); }
    304312while                   { KEYWORD_RETURN(WHILE); }
     
    308316                                /* identifier */
    309317{identifier}    { IDENTIFIER_RETURN(); }
     318"`"{identifier}"`" {                                                                    // CFA
     319        yytext[yyleng - 1] = '\0'; yytext += 1;                         // SKULLDUGGERY: remove backquotes (ok to shorten?)
     320        IDENTIFIER_RETURN();
     321}
    310322{attr_identifier} { ATTRIBUTE_RETURN(); }
    311 "`"                             { BEGIN BKQUOTE; }
    312 <BKQUOTE>{identifier} { IDENTIFIER_RETURN(); }
    313 <BKQUOTE>"`"    { BEGIN 0; }
    314323
    315324                                /* numeric constants */
     325{binary_constant} { NUMERIC_RETURN(INTEGERconstant); }
     326{octal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    316327{decimal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    317 {octal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    318328{hex_constant}  { NUMERIC_RETURN(INTEGERconstant); }
    319329{floating_decimal}      { NUMERIC_RETURN(FLOATING_DECIMALconstant); } // must appear before floating_constant
     
    325335({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); }
    326336<QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); }
    327 <QUOTE>['\n]{user_suffix_opt}   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
     337<QUOTE>['\n]    { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
    328338                                /* ' stop editor highlighting */
    329339
     
    331341({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); }
    332342<STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); }
    333 <STRING>["\n]{user_suffix_opt}  { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
     343<STRING>["\n]   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
    334344                                /* " stop editor highlighting */
    335345
     
    341351                                /* punctuation */
    342352"@"                             { ASCIIOP_RETURN(); }
     353"`"                             { ASCIIOP_RETURN(); }
    343354"["                             { ASCIIOP_RETURN(); }
    344355"]"                             { ASCIIOP_RETURN(); }
     
    399410">>="                   { NAMEDOP_RETURN(RSassign); }
    400411
     412"~="                    { NAMEDOP_RETURN(Erange); }                             // CFA
    401413"@="                    { NAMEDOP_RETURN(ATassign); }                   // CFA
    402414
     
    405417"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
    406418"^?{}"                  { IDENTIFIER_RETURN(); }
    407 "?`"{identifier} { IDENTIFIER_RETURN(); }                               // unit operator
     419"?`"{identifier} { IDENTIFIER_RETURN(); }                               // postfix operator
    408420"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    409421        /*
     
    448460
    449461%%
     462
    450463// ----end of lexer----
    451464
    452465void yyerror( const char * errmsg ) {
    453         cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1
    454                  << ": " << SemanticError::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
     466        SemanticErrorThrow = true;
     467        cerr << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1
     468                 << ": " << ErrorHelpers::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
    455469}
    456470
Note: See TracChangeset for help on using the changeset viewer.