Changeset b3f252a for src/Parser
- Timestamp:
- Sep 7, 2017, 10:36:35 AM (8 years ago)
- 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. - Location:
- src/Parser
- Files:
-
- 7 edited
-
ExpressionNode.cc (modified) (15 diffs)
-
ParseNode.h (modified) (6 diffs)
-
StatementNode.cc (modified) (3 diffs)
-
TypeData.cc (modified) (2 diffs)
-
TypeData.h (modified) (2 diffs)
-
lex.ll (modified) (10 diffs)
-
parser.yy (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r871cdb4 rb3f252a 7 7 // ExpressionNode.cc -- 8 8 // 9 // Author : Rodolfo G. Esteves9 // Author : Peter A. Buhr 10 10 // Created On : Sat May 16 13:17:07 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Aug 2 11:12:00201713 // Update Count : 56811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 22:21:21 2017 13 // Update Count : 639 14 14 // 15 15 … … 58 58 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 59 59 60 Expression * build_constantInteger( const std::string & str ) { 60 static 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 68 Expression * build_constantInteger( string & str ) { 61 69 static const BasicType::Kind kind[2][3] = { 62 70 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 63 71 { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 64 72 }; 73 74 string units; // units 75 sepNumeric( str, units ); // separate constant from units 76 65 77 bool dec = true, Unsigned = false; // decimal, unsigned constant 66 78 int size; // 0 => int, 1 => long, 2 => long long … … 69 81 Expression * ret; 70 82 83 // ROB: what do we do with units on 0 and 1? 71 84 // special constants 72 85 if ( str == "0" ) { … … 134 147 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 135 148 CLEANUP: 149 if ( units.length() != 0 ) { 150 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 151 } // if 152 136 153 delete &str; // created by lex 137 154 return ret; 138 155 } // build_constantInteger 139 156 140 Expression * build_constantFloat( const std::string & str ) {157 Expression * build_constantFloat( string & str ) { 141 158 static const BasicType::Kind kind[2][3] = { 142 159 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, 143 160 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, 144 161 }; 162 163 string units; // units 164 sepNumeric( str, units ); // separate constant from units 145 165 146 166 bool complx = false; // real, complex … … 169 189 170 190 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 171 195 delete &str; // created by lex 172 196 return ret; 173 197 } // build_constantFloat 174 198 175 Expression * build_constantChar( const std::string & str ) { 199 static 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 207 Expression * build_constantChar( string & str ) { 208 string units; // units 209 sepString( str, units, '\'' ); // separate constant from units 210 176 211 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 177 216 delete &str; // created by lex 178 217 return ret; 179 218 } // build_constantChar 180 219 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 220 Expression * 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 187 245 delete &str; // created by lex 188 246 return ret; 189 247 } // build_constantStr 190 248 191 Expression * build_field_name_FLOATINGconstant( const st d::string & str ) {249 Expression * build_field_name_FLOATINGconstant( const string & str ) { 192 250 // str is of the form A.B -> separate at the . and return member expression 193 251 int a, b; 194 252 char dot; 195 st d::stringstream ss( str );253 stringstream ss( str ); 196 254 ss >> a >> dot >> b; 197 255 UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) ); … … 207 265 } else { 208 266 return new UntypedMemberExpr( fracts, fieldName ); 209 } 210 } 267 } // if 268 } // if 211 269 return fieldName; 212 270 } // make_field_name_fraction_constants … … 216 274 } // build_field_name_fraction_constants 217 275 218 Expression * build_field_name_REALFRACTIONconstant( const st d::string & str ) {276 Expression * build_field_name_REALFRACTIONconstant( const string & str ) { 219 277 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str ); 220 Expression * ret = build_constantInteger( *new st d::string( str.substr(1) ) );278 Expression * ret = build_constantInteger( *new string( str.substr(1) ) ); 221 279 delete &str; 222 280 return ret; 223 281 } // build_field_name_REALFRACTIONconstant 224 282 225 Expression * build_field_name_REALDECIMALconstant( const st d::string & str ) {283 Expression * build_field_name_REALDECIMALconstant( const string & str ) { 226 284 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str ); 227 Expression * ret = build_constantInteger( *new st d::string( str.substr( 0, str.size()-1 ) ) );285 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) ); 228 286 delete &str; 229 287 return ret; … … 236 294 } // build_varref 237 295 238 296 // TODO: get rid of this and OperKinds and reuse code from OperatorTable 239 297 static const char * OperName[] = { // must harmonize with OperKinds 240 298 // diadic … … 244 302 "?[?]", "...", 245 303 // monadic 246 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&"304 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", 247 305 }; // OperName 248 306 … … 307 365 308 366 Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) { 309 std::list< Expression * > args;367 list< Expression * > args; 310 368 args.push_back( maybeMoveBuild< Expression >(expr_node) ); 311 369 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); … … 313 371 314 372 Expression * 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. 317 375 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 318 376 } // build_unary_ptr 319 377 320 378 Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 321 std::list< Expression * > args;379 list< Expression * > args; 322 380 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 323 381 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); … … 326 384 327 385 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 328 std::list< Expression * > args;386 list< Expression * > args; 329 387 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 330 388 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); … … 349 407 350 408 Expression * build_tuple( ExpressionNode * expr_node ) { 351 std::list< Expression * > exprs;409 list< Expression * > exprs; 352 410 buildMoveList( expr_node, exprs ); 353 411 return new UntypedTupleExpr( exprs );; … … 355 413 356 414 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 357 std::list< Expression * > args;415 list< Expression * > args; 358 416 buildMoveList( expr_node, args ); 359 417 return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr ); … … 364 422 } // build_range 365 423 366 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr* constraint, ExpressionNode * operand ) {424 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ) { 367 425 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) ); 368 426 } // build_asmexpr -
src/Parser/ParseNode.h
r871cdb4 rb3f252a 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thr Aug 17 13:46:00201713 // Update Count : 79 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 19:24:34 2017 13 // Update Count : 799 14 14 // 15 15 … … 154 154 Index, Range, 155 155 // monadic 156 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress,156 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, 157 157 Ctor, Dtor, 158 158 }; // OperKinds … … 162 162 }; 163 163 164 Expression * build_constantInteger( conststd::string &str );165 Expression * build_constantFloat( conststd::string &str );166 Expression * build_constantChar( conststd::string &str );167 ConstantExpr * build_constantStr( conststd::string &str );164 Expression * build_constantInteger( std::string &str ); 165 Expression * build_constantFloat( std::string &str ); 166 Expression * build_constantChar( std::string &str ); 167 Expression * build_constantStr( std::string &str ); 168 168 Expression * build_field_name_FLOATINGconstant( const std::string & str ); 169 169 Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ); … … 197 197 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ); 198 198 Expression * build_range( ExpressionNode * low, ExpressionNode * high ); 199 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr* constraint, ExpressionNode * operand );199 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ); 200 200 Expression * build_valexpr( StatementNode * s ); 201 201 Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ); … … 330 330 bool hasEllipsis; 331 331 LinkageSpec::Spec linkage; 332 ConstantExpr*asmName;332 Expression *asmName; 333 333 std::list< Attribute * > attributes; 334 334 InitializerNode * initializer; … … 413 413 Statement * build_finally( StatementNode * stmt ); 414 414 Statement * build_compound( StatementNode * first ); 415 Statement * build_asmstmt( bool voltile, ConstantExpr* instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );415 Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 416 416 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when ); 417 417 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing ); -
src/Parser/StatementNode.cc
r871cdb4 rb3f252a 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:01:31201713 // Update Count : 34 512 // Last Modified On : Fri Sep 1 23:25:23 2017 13 // Update Count : 346 14 14 // 15 15 … … 99 99 } // if 100 100 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 } 102 114 delete ctl; 103 return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init );115 return new IfStmt( noLabels, cond, thenb, elseb, init ); 104 116 } 105 117 … … 288 300 } 289 301 290 Statement *build_asmstmt( bool voltile, ConstantExpr*instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {302 Statement *build_asmstmt( bool voltile, Expression *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) { 291 303 std::list< Expression * > out, in; 292 304 std::list< ConstantExpr * > clob; -
src/Parser/TypeData.cc
r871cdb4 rb3f252a 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:12:51 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Aug 14 10:41:00201713 // Update Count : 56 811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 1 23:13:38 2017 13 // Update Count : 569 14 14 // 15 15 … … 814 814 } // buildTypeof 815 815 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 ) {816 Declaration * 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 ) { 817 817 if ( td->kind == TypeData::Function ) { 818 818 if ( td->function.idList ) { // KR function ? -
src/Parser/TypeData.h
r871cdb4 rb3f252a 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:18:36 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Aug 14 10:38:00201713 // Update Count : 1 8911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 1 23:33:45 2017 13 // Update Count : 190 14 14 // 15 15 … … 118 118 TupleType * buildTuple( const TypeData * ); 119 119 TypeofType * 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 * >() );120 Declaration * 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 * >() ); 121 121 FunctionType * buildFunction( const TypeData * ); 122 122 void buildKRFunction( const TypeData::Function_t & function ); -
src/Parser/lex.ll
r871cdb4 rb3f252a 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : T ue Aug 22 22:43:39201713 * Update Count : 5 5812 * Last Modified On : Thu Aug 31 21:30:10 2017 13 * Update Count : 598 14 14 */ 15 15 … … 19 19 20 20 %{ 21 // Th islexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been21 // The lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been 22 22 // performed and removed from the source. The only exceptions are preprocessor directives passed to the compiler (e.g., 23 23 // line-number directives) and C/C++ style comments, which are ignored. … … 25 25 //**************************** Includes and Defines **************************** 26 26 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 27 30 #include <string> 28 31 #include <cstdio> // FILENAME_MAX 32 using namespace std; 29 33 30 34 #include "ParseNode.h" … … 32 36 33 37 char *yyfilename; 34 st d::string *strtext;// accumulate parts of character and string constant value38 string *strtext; // accumulate parts of character and string constant value 35 39 36 40 #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 st d::string( yytext ); RETURN_LOCN( x )41 #define RETURN_VAL(x) yylval.tok.str = new string( yytext ); RETURN_LOCN( x ) 38 42 #define RETURN_CHAR(x) yylval.tok.str = nullptr; RETURN_LOCN( x ) 39 43 #define RETURN_STR(x) yylval.tok.str = strtext; RETURN_LOCN( x ) 40 44 41 45 #define WHITE_RETURN(x) // do nothing 42 #define NEWLINE_RETURN() WHITE_RETURN( '\n' )46 #define NEWLINE_RETURN() column = 0; WHITE_RETURN( '\n' ) 43 47 #define ASCIIOP_RETURN() RETURN_CHAR( (int)yytext[0] ) // single character operator 44 48 #define NAMEDOP_RETURN(x) RETURN_CHAR( x ) // multichar operator, with a name … … 53 57 yyleng = 0; 54 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 55 67 if ( yytext[i] != '_' ) { 56 68 yytext[yyleng] = yytext[i]; … … 77 89 attr_identifier "@"{identifier} 78 90 91 user_suffix_opt ("`"{identifier})? 92 79 93 // numeric constants, CFA: '_' in constant 80 94 hex_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]?)))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]?))))? 82 96 83 97 octal_digits ({octal})|({octal}({octal}|"_")*{octal}) 84 98 octal_prefix "0""_"? 85 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix }?99 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt}{user_suffix_opt} 86 100 87 101 nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal}) 88 decimal_constant {nonzero_digits}{integer_suffix }?102 decimal_constant {nonzero_digits}{integer_suffix_opt}{user_suffix_opt} 89 103 90 104 hex_digits ({hex})|({hex}({hex}|"_")*{hex}) 91 105 hex_prefix "0"[xX]"_"? 92 hex_constant {hex_prefix}{hex_digits}{integer_suffix}? 93 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"))? 94 110 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 95 real_decimal {decimal_digits}"."{exponent}?{floating_suffix }?96 real_fraction "."{decimal_digits}{exponent}?{floating_suffix }?111 real_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt}{user_suffix_opt} 112 real_fraction "."{decimal_digits}{exponent}?{floating_suffix_opt}{user_suffix_opt} 97 113 real_constant {decimal_digits}{real_fraction} 98 114 exponent "_"?[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}? 115 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix_opt}{user_suffix_opt} 102 116 103 117 binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits} 104 118 hex_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 }?119 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix_opt} 106 120 107 121 // character escape sequence, GCC: \e => esc character … … 154 168 memcpy( &filename, begin_string + 1, length ); // copy file name from yytext 155 169 filename[ length ] = '\0'; // terminate string with sentinel 156 // std::cout << "file " << filename << " line " << lineno << std::endl;170 //cout << "file " << filename << " line " << lineno << endl; 157 171 yylineno = lineno; 158 172 yyfilename = filename; … … 302 316 303 317 /* character constant, allows empty value */ 304 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }318 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); } 305 319 <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); } 307 321 /* ' stop highlighting */ 308 322 309 323 /* string constant */ 310 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }324 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); } 311 325 <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); } 313 327 /* " stop highlighting */ 314 328 … … 383 397 {op_unary}"?" { IDENTIFIER_RETURN(); } // unary 384 398 "?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); } 385 "^?{}" { IDENTIFIER_RETURN(); } 399 "^?{}" { IDENTIFIER_RETURN(); } 400 "?`"{identifier} { IDENTIFIER_RETURN(); } // unit operator 386 401 "?"{op_binary_over}"?" { IDENTIFIER_RETURN(); } // binary 387 402 /* … … 422 437 } 423 438 424 /* unknown character s*/425 . { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }439 /* unknown character */ 440 . { yyerror( "unknown character" ); } 426 441 427 442 %% 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 } 428 449 429 450 // Local Variables: // -
src/Parser/parser.yy
r871cdb4 rb3f252a 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Aug 26 17:50:19 201713 // Update Count : 27 1212 // Last Modified On : Sun Sep 3 20:43:19 2017 13 // Update Count : 2742 14 14 // 15 15 … … 48 48 #include <cstdio> 49 49 #include <stack> 50 using namespace std; 51 50 52 #include "ParseNode.h" 51 53 #include "TypedefTable.h" 52 54 #include "TypeData.h" 53 55 #include "LinkageSpec.h" 54 using namespace std; 56 #include "Common/SemanticError.h" // error_str 55 57 56 58 extern DeclarationNode * parseTree; … … 98 100 StatementNode * sn; 99 101 WaitForStmt * wfs; 100 ConstantExpr* constant;102 Expression * constant; 101 103 IfCtl * ifctl; 102 104 ForCtl * fctl; … … 534 536 $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); 535 537 break; 538 case OperKinds::And: 539 $$ = new ExpressionNode( new AddressExpr( build_addressOf( $2 ) ) ); 540 break; 536 541 default: 537 542 assert( false ); … … 560 565 | ATTR_IDENTIFIER '(' type ')' 561 566 { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); } 562 // | ANDAND IDENTIFIER // GCC, address of label563 // { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2 ) ); }564 567 ; 565 568 … … 3133 3136 // ----end of grammar---- 3134 3137 3135 extern char *yytext;3136 3137 void yyerror( const char * ) {3138 cout << "Error ";3139 if ( yyfilename ) {3140 cout << "in file " << yyfilename << " ";3141 } // if3142 cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl;3143 }3144 3145 3138 // Local Variables: // 3146 3139 // mode: c++ //
Note:
See TracChangeset
for help on using the changeset viewer.