Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    r5b2edbc r76c62b2  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Tue Aug 22 22:43:39 2017
    13  * Update Count     : 558
     12 * Last Modified On : Thu Aug 31 21:30:10 2017
     13 * Update Count     : 598
    1414 */
    1515
     
    1919
    2020%{
    21 // This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been
     21// The 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
     27unsigned 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
    2730#include <string>
    2831#include <cstdio>                                                                               // FILENAME_MAX
     32using namespace std;
    2933
    3034#include "ParseNode.h"
     
    3236
    3337char *yyfilename;
    34 std::string *strtext;                                                                   // accumulate parts of character and string constant value
     38string *strtext;                                                                                // accumulate parts of character and string constant value
    3539
    3640#define RETURN_LOCN(x)          yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x )
    37 #define RETURN_VAL(x)           yylval.tok.str = new std::string( yytext ); RETURN_LOCN( x )
     41#define RETURN_VAL(x)           yylval.tok.str = new string( yytext ); RETURN_LOCN( x )
    3842#define RETURN_CHAR(x)          yylval.tok.str = nullptr; RETURN_LOCN( x )
    3943#define RETURN_STR(x)           yylval.tok.str = strtext; RETURN_LOCN( x )
    4044
    4145#define WHITE_RETURN(x)         // do nothing
    42 #define NEWLINE_RETURN()        WHITE_RETURN( '\n' )
     46#define NEWLINE_RETURN()        column = 0; WHITE_RETURN( '\n' )
    4347#define ASCIIOP_RETURN()        RETURN_CHAR( (int)yytext[0] ) // single character operator
    4448#define NAMEDOP_RETURN(x)       RETURN_CHAR( x )                        // multichar operator, with a name
     
    5357        yyleng = 0;
    5458        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
    5567                if ( yytext[i] != '_' ) {
    5668                        yytext[yyleng] = yytext[i];
     
    7789attr_identifier "@"{identifier}
    7890
     91user_suffix_opt ("`"{identifier})?
     92
    7993                                // numeric constants, CFA: '_' in constant
    8094hex_quad {hex}("_"?{hex}){3}
    81 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]?))))?
    8296
    8397octal_digits ({octal})|({octal}({octal}|"_")*{octal})
    8498octal_prefix "0""_"?
    85 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix}?
     99octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt}{user_suffix_opt}
    86100
    87101nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal})
    88 decimal_constant {nonzero_digits}{integer_suffix}?
     102decimal_constant {nonzero_digits}{integer_suffix_opt}{user_suffix_opt}
    89103
    90104hex_digits ({hex})|({hex}({hex}|"_")*{hex})
    91105hex_prefix "0"[xX]"_"?
    92 hex_constant {hex_prefix}{hex_digits}{integer_suffix}?
    93 
     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"))?
    94110decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal})
    95 real_decimal {decimal_digits}"."{exponent}?{floating_suffix}?
    96 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}
    97113real_constant {decimal_digits}{real_fraction}
    98114exponent "_"?[eE]"_"?[+-]?{decimal_digits}
    99                                 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)
    100 floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL")
    101 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}?
     115floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix_opt}{user_suffix_opt}
    102116
    103117binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits}
    104118hex_fractional_constant ({hex_digits}?"."{hex_digits})|({hex_digits}".")
    105 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}
    106120
    107121                                // character escape sequence, GCC: \e => esc character
     
    154168                memcpy( &filename, begin_string + 1, length );  // copy file name from yytext
    155169                filename[ length ] = '\0';                                              // terminate string with sentinel
    156                 //std::cout << "file " << filename << " line " << lineno << std::endl;
     170                //cout << "file " << filename << " line " << lineno << endl;
    157171                yylineno = lineno;
    158172                yyfilename = filename;
     
    237251__label__               { KEYWORD_RETURN(LABEL); }                              // GCC
    238252long                    { KEYWORD_RETURN(LONG); }
    239 lvalue                  { KEYWORD_RETURN(LVALUE); }                             // CFA
    240253monitor                 { KEYWORD_RETURN(MONITOR); }                    // CFA
    241254mutex                   { KEYWORD_RETURN(MUTEX); }                              // CFA
     
    303316
    304317                                /* character constant, allows empty value */
    305 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
     318({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); }
    306319<QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); }
    307 <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); }
    308321                                /* ' stop highlighting */
    309322
    310323                                /* string constant */
    311 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
     324({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); }
    312325<STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); }
    313 <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); }
    314327                                /* " stop highlighting */
    315328
     
    384397{op_unary}"?"   { IDENTIFIER_RETURN(); }                                // unary
    385398"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
    386 "^?{}" { IDENTIFIER_RETURN(); }
     399"^?{}"                  { IDENTIFIER_RETURN(); }
     400"?`"{identifier} { IDENTIFIER_RETURN(); }                               // unit operator
    387401"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    388402        /*
     
    423437}
    424438
    425                                 /* unknown characters */
    426 .                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
     439                                /* unknown character */
     440.                               { yyerror( "unknown character" ); }
    427441
    428442%%
     443// ----end of lexer----
     444
     445void yyerror( const char * errmsg ) {
     446        cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1
     447                 << ": " << SemanticError::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
     448}
    429449
    430450// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.