Changeset b3c7963 for src/Parser
- Timestamp:
- Sep 12, 2017, 5:55:31 PM (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:
- 4639b0d
- Parents:
- a506df4 (diff), a46478a (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
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
ra506df4 rb3c7963 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 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 1 15:07:09 201713 // Update Count : 6 1812 // Last Modified On : Tue Sep 12 10:00:29 2017 13 // Update Count : 672 14 14 // 15 15 … … 49 49 // type. 50 50 51 extern const Type::Qualifiers noQualifiers; // no qualifiers on constants 52 51 extern const Type::Qualifiers noQualifiers; // no qualifiers on constants 52 53 static inline bool checkH( char c ) { return c == 'h' || c == 'H'; } 54 static inline bool checkL( char c ) { return c == 'l' || c == 'L'; } 55 static inline bool checkZ( char c ) { return c == 'z' || c == 'Z'; } 53 56 static inline bool checkU( char c ) { return c == 'u' || c == 'U'; } 54 static inline bool checkL( char c ) { return c == 'l' || c == 'L'; }55 57 static inline bool checkF( char c ) { return c == 'f' || c == 'F'; } 56 58 static inline bool checkD( char c ) { return c == 'd' || c == 'D'; } … … 66 68 } // sepNumeric 67 69 68 Expression * build_constantInteger( std::string & str ) { 69 static const BasicType::Kind kind[2][3] = { 70 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 71 { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 70 Expression * build_constantInteger( string & str ) { 71 static const BasicType::Kind kind[2][5] = { 72 // short (h) must be before char (hh) 73 { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 74 { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 72 75 }; 73 76 … … 76 79 77 80 bool dec = true, Unsigned = false; // decimal, unsigned constant 78 int size; // 0 => int, 1 => long, 2 => long long81 int size; // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => size_t 79 82 unsigned long long int v; // converted integral value 80 83 size_t last = str.length() - 1; // last character of constant 81 84 Expression * ret; 82 85 83 // ROB: what do we do with units on 0 and 1?84 86 // special constants 85 87 if ( str == "0" ) { … … 107 109 108 110 if ( v <= INT_MAX ) { // signed int 109 size = 0;111 size = 2; 110 112 } else if ( v <= UINT_MAX && ! dec ) { // unsigned int 111 size = 0;113 size = 2; 112 114 Unsigned = true; // unsigned 113 115 } else if ( v <= LONG_MAX ) { // signed long int 114 size = 1;116 size = 3; 115 117 } else if ( v <= ULONG_MAX && ( ! dec || LONG_MAX == LLONG_MAX ) ) { // signed long int 116 size = 1;118 size = 3; 117 119 Unsigned = true; // unsigned long int 118 120 } else if ( v <= LLONG_MAX ) { // signed long long int 119 size = 2;121 size = 4; 120 122 } else { // unsigned long long int 121 size = 2;123 size = 4; 122 124 Unsigned = true; // unsigned long long int 123 125 } // if 126 127 // At least one digit in integer constant, so safe to backup while looking for suffix. 124 128 125 129 if ( checkU( str[last] ) ) { // suffix 'u' ? 126 130 Unsigned = true; 127 if ( last > 0 && checkL( str[last - 1] ) ) {// suffix 'l' ?128 size = 1;129 if ( last > 1 && checkL( str[last - 2] ) ) { // suffix 'll'?130 size = 2;131 if ( checkL( str[last - 1] ) ) { // suffix 'l' ? 132 size = 3; 133 if ( checkL( str[last - 2] ) ) { // suffix "ll" ? 134 size = 4; 131 135 } // if 136 } else if ( checkH( str[last - 1] ) ) { // suffix 'h' ? 137 size = 0; 138 if ( checkH( str[last - 2] ) ) { // suffix "hh" ? 139 size = 1; 140 } // if 141 str.erase( last - size - 1, size + 1 ); // remove 'h'/"hh" 132 142 } // if 133 143 } else if ( checkL( str[ last ] ) ) { // suffix 'l' ? 134 size = 1;135 if ( last > 0 && checkL( str[last - 1] ) ) {// suffix 'll' ?136 size = 2;137 if ( last > 1 && checkU( str[last - 2] ) ) {// suffix 'u' ?144 size = 3; 145 if ( checkL( str[last - 1] ) ) { // suffix 'll' ? 146 size = 4; 147 if ( checkU( str[last - 2] ) ) { // suffix 'u' ? 138 148 Unsigned = true; 139 149 } // if 140 } else { 141 if ( last > 0 && checkU( str[last - 1] ) ) { // suffix 'u' ? 150 } else if ( checkU( str[last - 1] ) ) { // suffix 'u' ? 151 Unsigned = true; 152 } // if 153 } else if ( checkH( str[ last ] ) ) { // suffix 'h' ? 154 size = 0; 155 if ( checkH( str[last - 1] ) ) { // suffix "hh" ? 156 size = 1; 157 if ( checkU( str[last - 2] ) ) { // suffix 'u' ? 142 158 Unsigned = true; 143 159 } // if 144 } // if 160 } else if ( checkU( str[last - 1] ) ) { // suffix 'u' ? 161 Unsigned = true; 162 } // if 163 str.erase( last - size, size + 1 ); // remove 'h'/"hh" 164 } else if ( checkZ( str[last] ) ) { // suffix 'z' ? 165 size = 5; 166 str.erase( last, 1 ); // remove 'z' 145 167 } // if 146 168 147 169 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 170 if ( Unsigned && size < 2 ) { // less than int ? 171 // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which eliminates warnings for large values. 172 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) ); 173 } else if ( size == 5 ) { // explicit cast to size_t 174 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), "size_t", false ) ); 175 } // if 148 176 CLEANUP: 149 177 if ( units.length() != 0 ) { 150 ret = new UntypedExpr( new NameExpr( units , ret ));178 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 151 179 } // if 152 180 … … 155 183 } // build_constantInteger 156 184 157 Expression * build_constantFloat( st d::string & str ) {185 Expression * build_constantFloat( string & str ) { 158 186 static const BasicType::Kind kind[2][3] = { 159 187 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, … … 190 218 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) ); 191 219 if ( units.length() != 0 ) { 192 ret = new UntypedExpr( new NameExpr( units , ret ));220 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 193 221 } // if 194 222 … … 205 233 } // sepString 206 234 207 Expression * build_constantChar( st d::string & str ) {235 Expression * build_constantChar( string & str ) { 208 236 string units; // units 209 237 sepString( str, units, '\'' ); // separate constant from units … … 211 239 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) ); 212 240 if ( units.length() != 0 ) { 213 ret = new UntypedExpr( new NameExpr( units , ret ));241 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 214 242 } // if 215 243 … … 218 246 } // build_constantChar 219 247 220 ConstantExpr * build_constantStr( std::string & str ) {248 Expression * build_constantStr( string & str ) { 221 249 string units; // units 222 250 sepString( str, units, '"' ); // separate constant from units 223 251 224 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), 252 BasicType::Kind strtype = BasicType::Char; // default string type 253 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" 254 case 'u': 255 if ( str[1] == '8' ) break; // utf-8 characters 256 strtype = BasicType::ShortUnsignedInt; 257 break; 258 case 'U': 259 strtype = BasicType::UnsignedInt; 260 break; 261 case 'L': 262 strtype = BasicType::SignedInt; 263 break; 264 } // switch 265 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), strtype ), 225 266 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 226 267 false, false ); 227 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 228 // ROB: type mismatch 229 // if ( units.length() != 0 ) { 230 // ret = new UntypedExpr( new NameExpr( units, ret ) ); 231 // } // if 268 Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 269 if ( units.length() != 0 ) { 270 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 271 } // if 232 272 233 273 delete &str; // created by lex … … 235 275 } // build_constantStr 236 276 237 Expression * build_field_name_FLOATINGconstant( const std::string & str ) { 277 Expression * build_field_name_FLOATING_FRACTIONconstant( const string & str ) { 278 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str ); 279 Expression * ret = build_constantInteger( *new string( str.substr(1) ) ); 280 delete &str; 281 return ret; 282 } // build_field_name_FLOATING_FRACTIONconstant 283 284 Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) { 285 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str ); 286 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) ); 287 delete &str; 288 return ret; 289 } // build_field_name_FLOATING_DECIMALconstant 290 291 Expression * build_field_name_FLOATINGconstant( const string & str ) { 238 292 // str is of the form A.B -> separate at the . and return member expression 239 293 int a, b; 240 294 char dot; 241 st d::stringstream ss( str );295 stringstream ss( str ); 242 296 ss >> a >> dot >> b; 243 297 UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) ); … … 253 307 } else { 254 308 return new UntypedMemberExpr( fracts, fieldName ); 255 } 256 } 309 } // if 310 } // if 257 311 return fieldName; 258 312 } // make_field_name_fraction_constants … … 261 315 return make_field_name_fraction_constants( fieldName, maybeMoveBuild< Expression >( fracts ) ); 262 316 } // build_field_name_fraction_constants 263 264 Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) {265 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );266 Expression * ret = build_constantInteger( *new std::string( str.substr(1) ) );267 delete &str;268 return ret;269 } // build_field_name_REALFRACTIONconstant270 271 Expression * build_field_name_REALDECIMALconstant( const std::string & str ) {272 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str );273 Expression * ret = build_constantInteger( *new std::string( str.substr( 0, str.size()-1 ) ) );274 delete &str;275 return ret;276 } // build_field_name_REALDECIMALconstant277 317 278 318 NameExpr * build_varref( const string * name ) { … … 353 393 354 394 Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) { 355 std::list< Expression * > args;395 list< Expression * > args; 356 396 args.push_back( maybeMoveBuild< Expression >(expr_node) ); 357 397 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); … … 359 399 360 400 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) { 361 std::list< Expression * > args;401 list< Expression * > args; 362 402 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code. 363 403 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); … … 365 405 366 406 Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 367 std::list< Expression * > args;407 list< Expression * > args; 368 408 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 369 409 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); … … 372 412 373 413 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 374 std::list< Expression * > args;414 list< Expression * > args; 375 415 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 376 416 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); … … 395 435 396 436 Expression * build_tuple( ExpressionNode * expr_node ) { 397 std::list< Expression * > exprs;437 list< Expression * > exprs; 398 438 buildMoveList( expr_node, exprs ); 399 439 return new UntypedTupleExpr( exprs );; … … 401 441 402 442 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 403 std::list< Expression * > args;443 list< Expression * > args; 404 444 buildMoveList( expr_node, args ); 405 445 return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr ); … … 410 450 } // build_range 411 451 412 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr* constraint, ExpressionNode * operand ) {452 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ) { 413 453 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) ); 414 454 } // build_asmexpr -
src/Parser/ParseNode.h
ra506df4 rb3c7963 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 31 17:42:49201713 // Update Count : 79712 // Last Modified On : Sun Sep 10 09:56:32 2017 13 // Update Count : 801 14 14 // 15 15 … … 165 165 Expression * build_constantFloat( std::string &str ); 166 166 Expression * build_constantChar( std::string &str ); 167 ConstantExpr * build_constantStr( std::string &str ); 167 Expression * build_constantStr( std::string &str ); 168 Expression * build_field_name_FLOATING_FRACTIONconstant( const std::string & str ); 169 Expression * build_field_name_FLOATING_DECIMALconstant( const std::string & str ); 168 170 Expression * build_field_name_FLOATINGconstant( const std::string & str ); 169 171 Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ); 170 Expression * build_field_name_REALFRACTIONconstant( const std::string & str );171 Expression * build_field_name_REALDECIMALconstant( const std::string & str );172 172 173 173 NameExpr * build_varref( const std::string * name ); … … 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
ra506df4 rb3c7963 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 … … 300 300 } 301 301 302 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 ) { 303 303 std::list< Expression * > out, in; 304 304 std::list< ConstantExpr * > clob; -
src/Parser/TypeData.cc
ra506df4 rb3c7963 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
ra506df4 rb3c7963 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
ra506df4 rb3c7963 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Thu Aug 31 21:30:10201713 * Update Count : 59812 * Last Modified On : Sun Sep 10 22:29:15 2017 13 * Update Count : 620 14 14 */ 15 15 … … 93 93 // numeric constants, CFA: '_' in constant 94 94 hex_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]?))))? 95 length ("ll"|"LL"|[lL])|("hh"|"HH"|[hH]) 96 integer_suffix_opt ("_"?(([uU]({length}?[iI]?)|([iI]{length}))|([iI]({length}?[uU]?)|([uU]{length}))|({length}([iI]?[uU]?)|([uU][iI]))|[zZ]))?{user_suffix_opt} 96 97 97 98 octal_digits ({octal})|({octal}({octal}|"_")*{octal}) 98 99 octal_prefix "0""_"? 99 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt} {user_suffix_opt}100 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt} 100 101 101 102 nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal}) 102 decimal_constant {nonzero_digits}{integer_suffix_opt} {user_suffix_opt}103 decimal_constant {nonzero_digits}{integer_suffix_opt} 103 104 104 105 hex_digits ({hex})|({hex}({hex}|"_")*{hex}) 105 106 hex_prefix "0"[xX]"_"? 106 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt} {user_suffix_opt}107 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt} 107 108 108 109 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 109 floating_suffix_opt ("_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL"))? 110 exponent "_"?[eE]"_"?[+-]?{decimal_digits} 111 floating_suffix ([fFdDlL]?[iI]?)|([iI][lLfFdD]) 112 floating_suffix_opt ("_"?({floating_suffix}|"DL"))?{user_suffix_opt} 110 113 decimal_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} 113 real_constant {decimal_digits}{real_fraction} 114 exponent "_"?[eE]"_"?[+-]?{decimal_digits} 115 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix_opt}{user_suffix_opt} 114 floating_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt} 115 floating_fraction "."{decimal_digits}{exponent}?{floating_suffix_opt} 116 floating_constant ({decimal_digits}{exponent}{floating_suffix_opt})|({decimal_digits}{floating_fraction}) 116 117 117 118 binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits} 118 hex_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} 119 hex_floating_suffix_opt ("_"?({floating_suffix}))?{user_suffix_opt} 120 hex_floating_fraction ({hex_digits}?"."{hex_digits})|({hex_digits}".") 121 hex_floating_constant {hex_prefix}(({hex_floating_fraction}{binary_exponent})|({hex_digits}{binary_exponent})){hex_floating_suffix_opt} 120 122 121 123 // character escape sequence, GCC: \e => esc character 122 124 simple_escape "\\"[abefnrtv'"?\\] 123 // ' stop highlighting125 // ' stop editor highlighting 124 126 octal_escape "\\"{octal}("_"?{octal}){0,2} 125 127 hex_escape "\\""x""_"?{hex_digits} … … 154 156 /* line directives */ 155 157 ^{h_white}*"#"{h_white}*[0-9]+{h_white}*["][^"\n]+["].*"\n" { 156 /* " stop highlighting */158 /* " stop editor highlighting */ 157 159 static char filename[FILENAME_MAX]; // temporarily store current source-file name 158 160 char *end_num; … … 310 312 {octal_constant} { NUMERIC_RETURN(INTEGERconstant); } 311 313 {hex_constant} { NUMERIC_RETURN(INTEGERconstant); } 312 { real_decimal} { NUMERIC_RETURN(REALDECIMALconstant); } // must appear before floating_constant313 { real_fraction} { NUMERIC_RETURN(REALFRACTIONconstant); } // must appear before floating_constant314 {floating_decimal} { NUMERIC_RETURN(FLOATING_DECIMALconstant); } // must appear before floating_constant 315 {floating_fraction} { NUMERIC_RETURN(FLOATING_FRACTIONconstant); } // must appear before floating_constant 314 316 {floating_constant} { NUMERIC_RETURN(FLOATINGconstant); } 315 317 {hex_floating_constant} { NUMERIC_RETURN(FLOATINGconstant); } … … 319 321 <QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); } 320 322 <QUOTE>['\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); } 321 /* ' stop highlighting */323 /* ' stop editor highlighting */ 322 324 323 325 /* string constant */ … … 325 327 <STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); } 326 328 <STRING>["\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); } 327 /* " stop highlighting */329 /* " stop editor highlighting */ 328 330 329 331 /* common character/string constant */ -
src/Parser/parser.yy
ra506df4 rb3c7963 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 30 07:04:19201713 // Update Count : 27 4012 // Last Modified On : Mon Sep 11 18:12:00 2017 13 // Update Count : 2787 14 14 // 15 15 … … 43 43 #define YYDEBUG_LEXER_TEXT (yylval) // lexer loads this up each time 44 44 #define YYDEBUG 1 // get the pretty debugging code to compile 45 #define YYERROR_VERBOSE 45 46 46 47 #undef __GNUC_MINOR__ … … 62 63 stack< LinkageSpec::Spec > linkageStack; 63 64 64 void appendStr( string *to, string *from ) { 65 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string. 66 to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) ); 65 bool appendStr( string & to, string & from ) { 66 // 1. Multiple strings are concatenated into a single string but not combined internally. The reason is that 67 // "\x12" "3" is treated as 2 characters versus 1 because "escape sequences are converted into single members of 68 // the execution character set just prior to adjacent string literal concatenation" (C11, Section 6.4.5-8). It is 69 // easier to let the C compiler handle this case. 70 // 71 // 2. String encodings are transformed into canonical form (one encoding at start) so the encoding can be found 72 // without searching the string, e.g.: "abc" L"def" L"ghi" => L"abc" "def" "ghi". Multiple encodings must match, 73 // i.e., u"a" U"b" L"c" is disallowed. 74 75 if ( from[0] != '"' ) { // encoding ? 76 if ( to[0] != '"' ) { // encoding ? 77 if ( to[0] != from[0] || to[1] != from[1] ) { // different encodings ? 78 yyerror( "non-matching string encodings for string-literal concatenation" ); 79 return false; // parse error, must call YYERROR in action 80 } else if ( from[1] == '8' ) { 81 from.erase( 0, 1 ); // remove 2nd encoding 82 } // if 83 } else { 84 if ( from[1] == '8' ) { // move encoding to start 85 to = "u8" + to; 86 from.erase( 0, 1 ); // remove 2nd encoding 87 } else { 88 to = from[0] + to; 89 } // if 90 } // if 91 from.erase( 0, 1 ); // remove 2nd encoding 92 } // if 93 to += " " + from; // concatenated into single string 94 return true; 67 95 } // appendStr 68 96 … … 89 117 %} 90 118 119 %define parse.error verbose 120 91 121 // Types declaration 92 122 %union … … 100 130 StatementNode * sn; 101 131 WaitForStmt * wfs; 102 ConstantExpr* constant;132 Expression * constant; 103 133 IfCtl * ifctl; 104 134 ForCtl * fctl; … … 146 176 // overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically 147 177 // converted into the tuple index (.)(1). e.g., 3.x 148 %token<tok> REALDECIMALconstant REALFRACTIONconstant FLOATINGconstant178 %token<tok> FLOATING_DECIMALconstant FLOATING_FRACTIONconstant FLOATINGconstant 149 179 150 180 // multi-character operators … … 315 345 %precedence ELSE // token precedence for start of else clause in IF/WAITFOR statement 316 346 347 317 348 %start translation_unit // parse-tree root 318 349 … … 321 352 322 353 // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols 323 // "identifier" and "TYPEDEFname" that are lexically identical. While it is possible to write a purely context-free324 // grammar, such a grammar would obscure the relationship between syntactic and semantic constructs. Hence, this325 // grammar uses the ANSI style.354 // "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical. While it is possible to write a purely 355 // context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs. 356 // Hence, this grammar uses the ANSI style. 326 357 // 327 358 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those … … 360 391 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 361 392 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); } 362 | REALDECIMALconstant{ $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }363 | REALFRACTIONconstant{ $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }393 | FLOATING_DECIMALconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 394 | FLOATING_FRACTIONconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 364 395 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 365 396 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 ) ); } … … 390 421 | string_literal_list STRINGliteral 391 422 { 392 appendStr( $1, $2 );// append 2nd juxtaposed string to 1st423 if ( ! appendStr( *$1, *$2 ) ) YYERROR; // append 2nd juxtaposed string to 1st 393 424 delete $2; // allocated by lexer 394 425 $$ = $1; // conversion from tok to str … … 434 465 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 435 466 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); } 436 | postfix_expression REALFRACTIONconstant// CFA, tuple index437 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_ REALFRACTIONconstant( *$2 ) ) ); }467 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 468 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); } 438 469 | postfix_expression ARROW no_attr_identifier 439 470 { … … 479 510 field: // CFA, tuple field selector 480 511 field_name 481 | REALDECIMALconstant field482 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_ REALDECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }483 | REALDECIMALconstant '[' push field_list pop ']'484 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_ REALDECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }512 | FLOATING_DECIMALconstant field 513 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); } 514 | FLOATING_DECIMALconstant '[' push field_list pop ']' 515 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); } 485 516 | field_name '.' field 486 517 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } … … 507 538 // empty 508 539 { $$ = nullptr; } 509 | fraction_constants REALFRACTIONconstant510 { 511 Expression * constant = build_field_name_ REALFRACTIONconstant( *$2 );540 | fraction_constants FLOATING_FRACTIONconstant 541 { 542 Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 ); 512 543 $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1, constant ) ) : new ExpressionNode( constant ); 513 544 }
Note:
See TracChangeset
for help on using the changeset viewer.