Changeset 76c62b2 for src/Parser/lex.ll


Ignore:
Timestamp:
Aug 31, 2017, 10:30:37 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, 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:
51c6353, e8ccca3
Parents:
2ad507b8
Message:

first attempt at user-defined constants (units)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    r2ad507b8 r76c62b2  
    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 : Thu Aug 31 21:30:10 2017
     13 * Update Count     : 598
    1414 */
    1515
     
    5757        yyleng = 0;
    5858        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
    5967                if ( yytext[i] != '_' ) {
    6068                        yytext[yyleng] = yytext[i];
     
    8189attr_identifier "@"{identifier}
    8290
     91user_suffix_opt ("`"{identifier})?
     92
    8393                                // numeric constants, CFA: '_' in constant
    8494hex_quad {hex}("_"?{hex}){3}
    85 integer_suffix "_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?)))
     95integer_suffix_opt ("_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?))))?
    8696
    8797octal_digits ({octal})|({octal}({octal}|"_")*{octal})
    8898octal_prefix "0""_"?
    89 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix}?
     99octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt}{user_suffix_opt}
    90100
    91101nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal})
    92 decimal_constant {nonzero_digits}{integer_suffix}?
     102decimal_constant {nonzero_digits}{integer_suffix_opt}{user_suffix_opt}
    93103
    94104hex_digits ({hex})|({hex}({hex}|"_")*{hex})
    95105hex_prefix "0"[xX]"_"?
    96 hex_constant {hex_prefix}{hex_digits}{integer_suffix}?
    97 
     106hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt}{user_suffix_opt}
     107
     108                                // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)
     109floating_suffix_opt ("_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL"))?
    98110decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal})
    99 real_decimal {decimal_digits}"."{exponent}?{floating_suffix}?
    100 real_fraction "."{decimal_digits}{exponent}?{floating_suffix}?
     111real_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt}{user_suffix_opt}
     112real_fraction "."{decimal_digits}{exponent}?{floating_suffix_opt}{user_suffix_opt}
    101113real_constant {decimal_digits}{real_fraction}
    102114exponent "_"?[eE]"_"?[+-]?{decimal_digits}
    103                                 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)
    104 floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL")
    105 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}?
     115floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix_opt}{user_suffix_opt}
    106116
    107117binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits}
    108118hex_fractional_constant ({hex_digits}?"."{hex_digits})|({hex_digits}".")
    109 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix}?
     119hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix_opt}
    110120
    111121                                // character escape sequence, GCC: \e => esc character
     
    308318({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); }
    309319<QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); }
    310 <QUOTE>['\n]    { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
     320<QUOTE>['\n]{user_suffix_opt}   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
    311321                                /* ' stop highlighting */
    312322
     
    314324({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); }
    315325<STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); }
    316 <STRING>["\n]   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
     326<STRING>["\n]{user_suffix_opt}  { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
    317327                                /* " stop highlighting */
    318328
     
    387397{op_unary}"?"   { IDENTIFIER_RETURN(); }                                // unary
    388398"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
    389 "^?{}" { IDENTIFIER_RETURN(); }
     399"^?{}"                  { IDENTIFIER_RETURN(); }
     400"?`"{identifier} { IDENTIFIER_RETURN(); }                               // unit operator
    390401"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    391402        /*
Note: See TracChangeset for help on using the changeset viewer.