Changeset b3f252a for src/Parser


Ignore:
Timestamp:
Sep 7, 2017, 10:36:35 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
e0886db
Parents:
871cdb4 (diff), 416cc86 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/Parser
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r871cdb4 rb3f252a  
    77// ExpressionNode.cc --
    88//
    9 // Author           : Rodolfo G. Esteves
     9// Author           : Peter A. Buhr
    1010// Created On       : Sat May 16 13:17:07 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  2 11:12:00 2017
    13 // Update Count     : 568
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Sep  3 22:21:21 2017
     13// Update Count     : 639
    1414//
    1515
     
    5858static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    5959
    60 Expression * build_constantInteger( const std::string & str ) {
     60static void sepNumeric( string & str, string & units ) {
     61        string::size_type posn = str.find_first_of( "`" );
     62        if ( posn != string::npos ) {
     63                units = "?" + str.substr( posn );                               // extract units
     64                str.erase( posn );                                                              // remove units
     65        } // if
     66} // sepNumeric
     67
     68Expression * build_constantInteger( string & str ) {
    6169        static const BasicType::Kind kind[2][3] = {
    6270                { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
    6371                { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },
    6472        };
     73
     74        string units;                                                                           // units
     75        sepNumeric( str, units );                                                       // separate constant from units
     76
    6577        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    6678        int size;                                                                                       // 0 => int, 1 => long, 2 => long long
     
    6981        Expression * ret;
    7082
     83        // ROB: what do we do with units on 0 and 1?
    7184        // special constants
    7285        if ( str == "0" ) {
     
    134147        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
    135148  CLEANUP:
     149        if ( units.length() != 0 ) {
     150                ret = new UntypedExpr( new NameExpr( units ), { ret } );
     151        } // if
     152
    136153        delete &str;                                                                            // created by lex
    137154        return ret;
    138155} // build_constantInteger
    139156
    140 Expression * build_constantFloat( const std::string & str ) {
     157Expression * build_constantFloat( string & str ) {
    141158        static const BasicType::Kind kind[2][3] = {
    142159                { BasicType::Float, BasicType::Double, BasicType::LongDouble },
    143160                { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex },
    144161        };
     162
     163        string units;                                                                           // units
     164        sepNumeric( str, units );                                                       // separate constant from units
    145165
    146166        bool complx = false;                                                            // real, complex
     
    169189
    170190        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
     191        if ( units.length() != 0 ) {
     192                ret = new UntypedExpr( new NameExpr( units ), { ret } );
     193        } // if
     194
    171195        delete &str;                                                                            // created by lex
    172196        return ret;
    173197} // build_constantFloat
    174198
    175 Expression * build_constantChar( const std::string & str ) {
     199static void sepString( string & str, string & units, char delimit ) {
     200        string::size_type posn = str.find_last_of( delimit ) + 1;
     201        if ( posn != str.length() ) {
     202                units = "?" + str.substr( posn );                               // extract units
     203                str.erase( posn );                                                              // remove units
     204        } // if
     205} // sepString
     206
     207Expression * build_constantChar( string & str ) {
     208        string units;                                                                           // units
     209        sepString( str, units, '\'' );                                          // separate constant from units
     210
    176211        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
     212        if ( units.length() != 0 ) {
     213                ret = new UntypedExpr( new NameExpr( units ), { ret } );
     214        } // if
     215
    177216        delete &str;                                                                            // created by lex
    178217        return ret;
    179218} // build_constantChar
    180219
    181 ConstantExpr * build_constantStr( const std::string & str ) {
    182         // string should probably be a primitive type
    183         ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
    184                                                                    new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
    185                                                                    false, false );
    186         ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
     220Expression * build_constantStr( string & str ) {
     221        string units;                                                                           // units
     222        sepString( str, units, '"' );                                           // separate constant from units
     223
     224        BasicType::Kind strtype = BasicType::Char;                      // default string type
     225        switch ( str[0] ) {                                                                     // str has >= 2 characters, i.e, null string ""
     226          case 'u':
     227                if ( str[1] == '8' ) break;                                             // utf-8 characters
     228                strtype = BasicType::ShortUnsignedInt;
     229                break;
     230          case 'U':
     231                strtype = BasicType::UnsignedInt;
     232                break;
     233          case 'L':
     234                strtype = BasicType::SignedInt;
     235                break;
     236        } // switch
     237        ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), strtype ),
     238                                                                        new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
     239                                                                        false, false );
     240        Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
     241        if ( units.length() != 0 ) {
     242                ret = new UntypedExpr( new NameExpr( units ), { ret } );
     243        } // if
     244
    187245        delete &str;                                                                            // created by lex
    188246        return ret;
    189247} // build_constantStr
    190248
    191 Expression * build_field_name_FLOATINGconstant( const std::string & str ) {
     249Expression * build_field_name_FLOATINGconstant( const string & str ) {
    192250        // str is of the form A.B -> separate at the . and return member expression
    193251        int a, b;
    194252        char dot;
    195         std::stringstream ss( str );
     253        stringstream ss( str );
    196254        ss >> a >> dot >> b;
    197255        UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) );
     
    207265                } else {
    208266                        return new UntypedMemberExpr( fracts, fieldName );
    209                 }
    210         }
     267                } // if
     268        } // if
    211269        return fieldName;
    212270} // make_field_name_fraction_constants
     
    216274} // build_field_name_fraction_constants
    217275
    218 Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) {
     276Expression * build_field_name_REALFRACTIONconstant( const string & str ) {
    219277        if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );
    220         Expression * ret = build_constantInteger( *new std::string( str.substr(1) ) );
     278        Expression * ret = build_constantInteger( *new string( str.substr(1) ) );
    221279        delete &str;
    222280        return ret;
    223281} // build_field_name_REALFRACTIONconstant
    224282
    225 Expression * build_field_name_REALDECIMALconstant( const std::string & str ) {
     283Expression * build_field_name_REALDECIMALconstant( const string & str ) {
    226284        if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str );
    227         Expression * ret = build_constantInteger( *new std::string( str.substr( 0, str.size()-1 ) ) );
     285        Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) );
    228286        delete &str;
    229287        return ret;
     
    236294} // build_varref
    237295
    238 
     296// TODO: get rid of this and OperKinds and reuse code from OperatorTable
    239297static const char * OperName[] = {                                              // must harmonize with OperKinds
    240298        // diadic
     
    244302        "?[?]", "...",
    245303        // monadic
    246         "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&"
     304        "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--",
    247305}; // OperName
    248306
     
    307365
    308366Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) {
    309         std::list< Expression * > args;
     367        list< Expression * > args;
    310368        args.push_back( maybeMoveBuild< Expression >(expr_node) );
    311369        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
     
    313371
    314372Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
    315         std::list< Expression * > args;
    316         args.push_back(  maybeMoveBuild< Expression >(expr_node) ); // xxx
     373        list< Expression * > args;
     374        args.push_back(  maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.
    317375        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    318376} // build_unary_ptr
    319377
    320378Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    321         std::list< Expression * > args;
     379        list< Expression * > args;
    322380        args.push_back( maybeMoveBuild< Expression >(expr_node1) );
    323381        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
     
    326384
    327385Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    328         std::list< Expression * > args;
     386        list< Expression * > args;
    329387        args.push_back( maybeMoveBuild< Expression >(expr_node1) );
    330388        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
     
    349407
    350408Expression * build_tuple( ExpressionNode * expr_node ) {
    351         std::list< Expression * > exprs;
     409        list< Expression * > exprs;
    352410        buildMoveList( expr_node, exprs );
    353411        return new UntypedTupleExpr( exprs );;
     
    355413
    356414Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
    357         std::list< Expression * > args;
     415        list< Expression * > args;
    358416        buildMoveList( expr_node, args );
    359417        return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
     
    364422} // build_range
    365423
    366 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand ) {
     424Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ) {
    367425        return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );
    368426} // build_asmexpr
  • src/Parser/ParseNode.h

    r871cdb4 rb3f252a  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 13:46:00 2017
    13 // Update Count     : 795
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Sep  3 19:24:34 2017
     13// Update Count     : 799
    1414//
    1515
     
    154154        Index, Range,
    155155        // monadic
    156         UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress,
     156        UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost,
    157157        Ctor, Dtor,
    158158}; // OperKinds
     
    162162};
    163163
    164 Expression * build_constantInteger( const std::string &str );
    165 Expression * build_constantFloat( const std::string &str );
    166 Expression * build_constantChar( const std::string &str );
    167 ConstantExpr * build_constantStr( const std::string &str );
     164Expression * build_constantInteger( std::string &str );
     165Expression * build_constantFloat( std::string &str );
     166Expression * build_constantChar( std::string &str );
     167Expression * build_constantStr( std::string &str );
    168168Expression * build_field_name_FLOATINGconstant( const std::string & str );
    169169Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts );
     
    197197Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node );
    198198Expression * build_range( ExpressionNode * low, ExpressionNode * high );
    199 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand );
     199Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand );
    200200Expression * build_valexpr( StatementNode * s );
    201201Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids );
     
    330330        bool hasEllipsis;
    331331        LinkageSpec::Spec linkage;
    332         ConstantExpr *asmName;
     332        Expression *asmName;
    333333        std::list< Attribute * > attributes;
    334334        InitializerNode * initializer;
     
    413413Statement * build_finally( StatementNode * stmt );
    414414Statement * build_compound( StatementNode * first );
    415 Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
     415Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
    416416WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when );
    417417WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing );
  • src/Parser/StatementNode.cc

    r871cdb4 rb3f252a  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 16:01:31 2017
    13 // Update Count     : 345
     12// Last Modified On : Fri Sep  1 23:25:23 2017
     13// Update Count     : 346
    1414//
    1515
     
    9999        } // if
    100100
    101         Expression * cond = ctl->condition ? maybeMoveBuild< Expression >(ctl->condition) : new VariableExpr( dynamic_cast<DeclarationWithType *>( dynamic_cast<DeclStmt *>( init.back() )->decl ) );
     101        Expression * cond = nullptr;
     102        if ( ctl->condition ) {
     103                // compare the provided condition against 0
     104                cond =  notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) );
     105        } else {
     106                for ( Statement * stmt : init ) {
     107                        // build the && of all of the declared variables compared against 0
     108                        DeclStmt * declStmt = safe_dynamic_cast< DeclStmt * >( stmt );
     109                        DeclarationWithType * dwt = safe_dynamic_cast< DeclarationWithType * >( declStmt->decl );
     110                        Expression * nze = notZeroExpr( new VariableExpr( dwt ) );
     111                        cond = cond ? new LogicalExpr( cond, nze, true ) : nze;
     112                }
     113        }
    102114        delete ctl;
    103         return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init );
     115        return new IfStmt( noLabels, cond, thenb, elseb, init );
    104116}
    105117
     
    288300}
    289301
    290 Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {
     302Statement *build_asmstmt( bool voltile, Expression *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {
    291303        std::list< Expression * > out, in;
    292304        std::list< ConstantExpr * > clob;
  • src/Parser/TypeData.cc

    r871cdb4 rb3f252a  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:12:51 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Aug 14 10:41:00 2017
    13 // Update Count     : 568
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Sep  1 23:13:38 2017
     13// Update Count     : 569
    1414//
    1515
     
    814814} // buildTypeof
    815815
    816 Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, ConstantExpr *asmName, Initializer * init, std::list< Attribute * > attributes ) {
     816Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, Expression *asmName, Initializer * init, std::list< Attribute * > attributes ) {
    817817        if ( td->kind == TypeData::Function ) {
    818818                if ( td->function.idList ) {                                    // KR function ?
  • src/Parser/TypeData.h

    r871cdb4 rb3f252a  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:18:36 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Aug 14 10:38:00 2017
    13 // Update Count     : 189
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Sep  1 23:33:45 2017
     13// Update Count     : 190
    1414//
    1515
     
    118118TupleType * buildTuple( const TypeData * );
    119119TypeofType * buildTypeof( const TypeData * );
    120 Declaration * buildDecl( const TypeData *, const std::string &, Type::StorageClasses, Expression *, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
     120Declaration * buildDecl( const TypeData *, const std::string &, Type::StorageClasses, Expression *, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec, Expression * asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
    121121FunctionType * buildFunction( const TypeData * );
    122122void buildKRFunction( const TypeData::Function_t & function );
  • src/Parser/lex.ll

    r871cdb4 rb3f252a  
    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;
     
    302316
    303317                                /* character constant, allows empty value */
    304 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
     318({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); }
    305319<QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); }
    306 <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); }
    307321                                /* ' stop highlighting */
    308322
    309323                                /* string constant */
    310 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string( yytext, yyleng ); }
     324({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); }
    311325<STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); }
    312 <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); }
    313327                                /* " stop highlighting */
    314328
     
    383397{op_unary}"?"   { IDENTIFIER_RETURN(); }                                // unary
    384398"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
    385 "^?{}" { IDENTIFIER_RETURN(); }
     399"^?{}"                  { IDENTIFIER_RETURN(); }
     400"?`"{identifier} { IDENTIFIER_RETURN(); }                               // unit operator
    386401"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    387402        /*
     
    422437}
    423438
    424                                 /* unknown characters */
    425 .                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
     439                                /* unknown character */
     440.                               { yyerror( "unknown character" ); }
    426441
    427442%%
     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}
    428449
    429450// Local Variables: //
  • src/Parser/parser.yy

    r871cdb4 rb3f252a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 26 17:50:19 2017
    13 // Update Count     : 2712
     12// Last Modified On : Sun Sep  3 20:43:19 2017
     13// Update Count     : 2742
    1414//
    1515
     
    4848#include <cstdio>
    4949#include <stack>
     50using namespace std;
     51
    5052#include "ParseNode.h"
    5153#include "TypedefTable.h"
    5254#include "TypeData.h"
    5355#include "LinkageSpec.h"
    54 using namespace std;
     56#include "Common/SemanticError.h"                                               // error_str
    5557
    5658extern DeclarationNode * parseTree;
     
    98100        StatementNode * sn;
    99101        WaitForStmt * wfs;
    100         ConstantExpr * constant;
     102        Expression * constant;
    101103        IfCtl * ifctl;
    102104        ForCtl * fctl;
     
    534536                                $$ = new ExpressionNode( build_unary_val( $1, $2 ) );
    535537                                break;
     538                          case OperKinds::And:
     539                                $$ = new ExpressionNode( new AddressExpr( build_addressOf( $2 ) ) );
     540                                break;
    536541                          default:
    537542                                assert( false );
     
    560565        | ATTR_IDENTIFIER '(' type ')'
    561566                { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); }
    562 //      | ANDAND IDENTIFIER                                                                     // GCC, address of label
    563 //              { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2 ) ); }
    564567        ;
    565568
     
    31333136// ----end of grammar----
    31343137
    3135 extern char *yytext;
    3136 
    3137 void yyerror( const char * ) {
    3138         cout << "Error ";
    3139         if ( yyfilename ) {
    3140                 cout << "in file " << yyfilename << " ";
    3141         } // if
    3142         cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl;
    3143 }
    3144 
    31453138// Local Variables: //
    31463139// mode: c++ //
Note: See TracChangeset for help on using the changeset viewer.