Changeset 1ebc1a62 in mainline for uspace/app/sbi/src/p_expr.c
- Timestamp:
- 2010-03-29T20:30:29Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a95310e
- Parents:
- 5da468e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/p_expr.c
r5da468e r1ebc1a62 31 31 #include <assert.h> 32 32 #include <stdlib.h> 33 #include "debug.h" 33 34 #include "lex.h" 34 35 #include "list.h" … … 57 58 static stree_expr_t *parse_self_ref(parse_t *parse); 58 59 59 /** Parse expression. */ 60 static stree_expr_t *parse_recovery_expr(parse_t *parse); 61 62 /** Parse expression. 63 * 64 * Input is read from the input object associated with @a parse. If any 65 * error occurs, parse->error will @c b_true when this function 66 * returns. parse->error_bailout will be @c b_true if the error has not 67 * been recovered yet. Similar holds for other parsing functions in this 68 * module. 69 * 70 * @param parse Parser object. 71 */ 60 72 stree_expr_t *parse_expr(parse_t *parse) 61 73 { 74 #ifdef DEBUG_PARSE_TRACE 75 printf("Parse expression.\n"); 76 #endif 77 if (parse_is_error(parse)) 78 return parse_recovery_expr(parse); 79 62 80 return parse_assign(parse); 63 81 } 64 82 65 /** Parse assignment expression. */ 83 /** Parse assignment expression. 84 * 85 * @param parse Parser object. 86 */ 66 87 static stree_expr_t *parse_assign(parse_t *parse) 67 88 { … … 93 114 } 94 115 95 /** Parse comparative expression. */ 116 /** Parse comparative expression. 117 * 118 * @param parse Parser object. 119 */ 96 120 static stree_expr_t *parse_comparative(parse_t *parse) 97 121 { … … 105 129 lcur_lc(parse) == lc_lt || lcur_lc(parse) == lc_gt || 106 130 lcur_lc(parse) == lc_lt_equal || lcur_lc(parse) == lc_gt_equal) { 131 132 if (parse_is_error(parse)) 133 break; 107 134 108 135 switch (lcur_lc(parse)) { … … 131 158 } 132 159 133 /** Parse additive expression. */ 160 /** Parse additive expression. 161 * 162 * @param parse Parser object. 163 */ 134 164 static stree_expr_t *parse_additive(parse_t *parse) 135 165 { … … 139 169 a = parse_prefix(parse); 140 170 while (lcur_lc(parse) == lc_plus) { 171 if (parse_is_error(parse)) 172 break; 173 141 174 lskip(parse); 142 175 b = parse_prefix(parse); … … 154 187 } 155 188 156 /** Parse prefix expression. */ 189 /** Parse prefix expression. 190 * 191 * @param parse Parser object. 192 */ 157 193 static stree_expr_t *parse_prefix(parse_t *parse) 158 194 { … … 162 198 case lc_plus: 163 199 printf("Unimplemented: Unary plus.\n"); 164 exit(1); 200 a = parse_recovery_expr(parse); 201 parse_note_error(parse); 202 break; 165 203 case lc_new: 166 204 a = parse_prefix_new(parse); … … 174 212 } 175 213 176 /** Parse @c new operator. */ 214 /** Parse @c new operator. 215 * 216 * @param parse Parser object. 217 */ 177 218 static stree_expr_t *parse_prefix_new(parse_t *parse) 178 219 { … … 198 239 } 199 240 200 /** Parse postfix expression. */ 241 /** Parse postfix expression. 242 * 243 * @param parse Parser object. 244 */ 201 245 static stree_expr_t *parse_postfix(parse_t *parse) 202 246 { … … 208 252 while (lcur_lc(parse) == lc_period || lcur_lc(parse) == lc_lparen || 209 253 lcur_lc(parse) == lc_lsbr || lcur_lc(parse) == lc_as) { 254 255 if (parse_is_error(parse)) 256 break; 210 257 211 258 switch (lcur_lc(parse)) { … … 232 279 } 233 280 234 /** Parse member access expression */ 281 /** Parse member access expression 282 * 283 * @param parse Parser object. 284 */ 235 285 static stree_expr_t *parse_pf_access(parse_t *parse, stree_expr_t *a) 236 286 { … … 252 302 } 253 303 254 /** Parse function call expression. */ 304 /** Parse function call expression. 305 * 306 * @param parse Parser object. 307 */ 255 308 static stree_expr_t *parse_pf_call(parse_t *parse, stree_expr_t *a) 256 309 { … … 268 321 269 322 if (lcur_lc(parse) != lc_rparen) { 270 while ( b_true) {323 while (!parse_is_error(parse)) { 271 324 arg = parse_expr(parse); 272 325 list_append(&call->args, arg); … … 286 339 } 287 340 288 /** Parse index expression. */ 341 /** Parse index expression. 342 * 343 * @param parse Parser object. 344 */ 289 345 static stree_expr_t *parse_pf_index(parse_t *parse, stree_expr_t *a) 290 346 { … … 302 358 303 359 if (lcur_lc(parse) != lc_rsbr) { 304 while ( b_true) {360 while (!parse_is_error(parse)) { 305 361 arg = parse_expr(parse); 306 362 list_append(&index->args, arg); … … 320 376 } 321 377 322 /** Parse @c as operator. */ 378 /** Parse @c as operator. 379 * 380 * @param parse Parser object. 381 */ 323 382 static stree_expr_t *parse_pf_as(parse_t *parse, stree_expr_t *a) 324 383 { … … 339 398 } 340 399 341 /** Parse primitive expression. */ 400 /** Parse primitive expression. 401 * 402 * @param parse Parser object. 403 */ 342 404 static stree_expr_t *parse_primitive(parse_t *parse) 343 405 { … … 362 424 default: 363 425 lunexpected_error(parse); 364 exit(1); 365 } 366 367 return expr; 368 } 369 370 /** Parse name reference. */ 426 expr = parse_recovery_expr(parse); 427 } 428 429 return expr; 430 } 431 432 /** Parse name reference. 433 * 434 * @param parse Parser object. 435 */ 371 436 static stree_expr_t *parse_nameref(parse_t *parse) 372 437 { … … 382 447 } 383 448 384 /** Parse integer literal. */ 449 /** Parse integer literal. 450 * 451 * @param parse Parser object. 452 */ 385 453 static stree_expr_t *parse_lit_int(parse_t *parse) 386 454 { … … 401 469 } 402 470 403 /** Parse reference literal (@c nil). */ 471 /** Parse reference literal (@c nil). 472 * 473 * @param parse Parser object. 474 */ 404 475 static stree_expr_t *parse_lit_ref(parse_t *parse) 405 476 { … … 417 488 } 418 489 419 /** Parse string literal. */ 490 /** Parse string literal. 491 * 492 * @param parse Parser object. 493 */ 420 494 static stree_expr_t *parse_lit_string(parse_t *parse) 421 495 { … … 436 510 } 437 511 438 /** Parse @c self keyword. */ 512 /** Parse @c self keyword. 513 * 514 * @param parse Parser object. 515 */ 439 516 static stree_expr_t *parse_self_ref(parse_t *parse) 440 517 { … … 451 528 return expr; 452 529 } 530 531 /** Construct a special recovery expression. 532 * 533 * @param parse Parser object. 534 */ 535 static stree_expr_t *parse_recovery_expr(parse_t *parse) 536 { 537 stree_literal_t *literal; 538 stree_expr_t *expr; 539 540 (void) parse; 541 542 literal = stree_literal_new(ltc_ref); 543 544 expr = stree_expr_new(ec_literal); 545 expr->u.literal = literal; 546 547 return expr; 548 }
Note:
See TracChangeset
for help on using the changeset viewer.