Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    r76c62b2 r5b2edbc  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Thu Aug 31 21:30:10 2017
    13  * Update Count     : 598
     12 * Last Modified On : Tue Aug 22 22:43:39 2017
     13 * Update Count     : 558
    1414 */
    1515
     
    1919
    2020%{
    21 // The lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been
     21// This 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
    27 unsigned 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 
    3027#include <string>
    3128#include <cstdio>                                                                               // FILENAME_MAX
    32 using namespace std;
    3329
    3430#include "ParseNode.h"
     
    3632
    3733char *yyfilename;
    38 string *strtext;                                                                                // accumulate parts of character and string constant value
     34std::string *strtext;                                                                   // accumulate parts of character and string constant value
    3935
    4036#define RETURN_LOCN(x)          yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x )
    41 #define RETURN_VAL(x)           yylval.tok.str = new string( yytext ); RETURN_LOCN( x )
     37#define RETURN_VAL(x)           yylval.tok.str = new std::string( yytext ); RETURN_LOCN( x )
    4238#define RETURN_CHAR(x)          yylval.tok.str = nullptr; RETURN_LOCN( x )
    4339#define RETURN_STR(x)           yylval.tok.str = strtext; RETURN_LOCN( x )
    4440
    4541#define WHITE_RETURN(x)         // do nothing
    46 #define NEWLINE_RETURN()        column = 0; WHITE_RETURN( '\n' )
     42#define NEWLINE_RETURN()        WHITE_RETURN( '\n' )
    4743#define ASCIIOP_RETURN()        RETURN_CHAR( (int)yytext[0] ) // single character operator
    4844#define NAMEDOP_RETURN(x)       RETURN_CHAR( x )                        // multichar operator, with a name
     
    5753        yyleng = 0;
    5854        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
    6755                if ( yytext[i] != '_' ) {
    6856                        yytext[yyleng] = yytext[i];
     
    8977attr_identifier "@"{identifier}
    9078
    91 user_suffix_opt ("`"{identifier})?
    92 
    9379                                // numeric constants, CFA: '_' in constant
    9480hex_quad {hex}("_"?{hex}){3}
    95 integer_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]?))))?
     81integer_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]?)))
    9682
    9783octal_digits ({octal})|({octal}({octal}|"_")*{octal})
    9884octal_prefix "0""_"?
    99 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt}{user_suffix_opt}
     85octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix}?
    10086
    10187nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal})
    102 decimal_constant {nonzero_digits}{integer_suffix_opt}{user_suffix_opt}
     88decimal_constant {nonzero_digits}{integer_suffix}?
    10389
    10490hex_digits ({hex})|({hex}({hex}|"_")*{hex})
    10591hex_prefix "0"[xX]"_"?
    106 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt}{user_suffix_opt}
    107 
    108                                 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)
    109 floating_suffix_opt ("_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL"))?
     92hex_constant {hex_prefix}{hex_digits}{integer_suffix}?
     93
    11094decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal})
    111 real_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt}{user_suffix_opt}
    112 real_fraction "."{decimal_digits}{exponent}?{floating_suffix_opt}{user_suffix_opt}
     95real_decimal {decimal_digits}"."{exponent}?{floating_suffix}?
     96real_fraction "."{decimal_digits}{exponent}?{floating_suffix}?
    11397real_constant {decimal_digits}{real_fraction}
    11498exponent "_"?[eE]"_"?[+-]?{decimal_digits}
    115 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix_opt}{user_suffix_opt}
     99                                // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)
     100floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL")
     101floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}?
    116102
    117103binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits}
    118104hex_fractional_constant ({hex_digits}?"."{hex_digits})|({hex_digits}".")
    119 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix_opt}
     105hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix}?
    120106
    121107                                // character escape sequence, GCC: \e => esc character
     
    168154                memcpy( &filename, begin_string + 1, length );  // copy file name from yytext
    169155                filename[ length ] = '\0';                                              // terminate string with sentinel
    170                 //cout << "file " << filename << " line " << lineno << endl;
     156                //std::cout << "file " << filename << " line " << lineno << std::endl;
    171157                yylineno = lineno;
    172158                yyfilename = filename;
     
    251237__label__               { KEYWORD_RETURN(LABEL); }                              // GCC
    252238long                    { KEYWORD_RETURN(LONG); }
     239lvalue                  { KEYWORD_RETURN(LVALUE); }                             // CFA
    253240monitor                 { KEYWORD_RETURN(MONITOR); }                    // CFA
    254241mutex                   { KEYWORD_RETURN(MUTEX); }                              // CFA
     
    316303
    317304                                /* character constant, allows empty value */
    318 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); }
     305({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
    319306<QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); }
    320 <QUOTE>['\n]{user_suffix_opt}   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
     307<QUOTE>['\n]    { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }
    321308                                /* ' stop highlighting */
    322309
    323310                                /* string constant */
    324 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); }
     311({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
    325312<STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); }
    326 <STRING>["\n]{user_suffix_opt}  { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
     313<STRING>["\n]   { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }
    327314                                /* " stop highlighting */
    328315
     
    397384{op_unary}"?"   { IDENTIFIER_RETURN(); }                                // unary
    398385"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
    399 "^?{}"                  { IDENTIFIER_RETURN(); }
    400 "?`"{identifier} { IDENTIFIER_RETURN(); }                               // unit operator
     386"^?{}" { IDENTIFIER_RETURN(); }
    401387"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    402388        /*
     
    437423}
    438424
    439                                 /* unknown character */
    440 .                               { yyerror( "unknown character" ); }
     425                                /* unknown characters */
     426.                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
    441427
    442428%%
    443 // ----end of lexer----
    444 
    445 void 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 }
    449429
    450430// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.