Changeset 23de644 in mainline for uspace/app/sbi/src/p_expr.c
- Timestamp:
- 2010-04-04T22:31:01Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 074444f, ecb6ac32
- Parents:
- 3aae4e8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/p_expr.c
r3aae4e8 r23de644 31 31 #include <assert.h> 32 32 #include <stdlib.h> 33 #include "bigint.h" 33 34 #include "debug.h" 34 35 #include "lex.h" … … 44 45 static stree_expr_t *parse_comparative(parse_t *parse); 45 46 static stree_expr_t *parse_additive(parse_t *parse); 47 static stree_expr_t *parse_multip(parse_t *parse); 46 48 static stree_expr_t *parse_prefix(parse_t *parse); 47 49 static stree_expr_t *parse_prefix_new(parse_t *parse); … … 51 53 static stree_expr_t *parse_pf_index(parse_t *parse, stree_expr_t *a); 52 54 static stree_expr_t *parse_pf_as(parse_t *parse, stree_expr_t *a); 55 static stree_expr_t *parse_paren(parse_t *parse); 53 56 static stree_expr_t *parse_primitive(parse_t *parse); 54 57 static stree_expr_t *parse_nameref(parse_t *parse); … … 166 169 stree_expr_t *a, *b, *tmp; 167 170 stree_binop_t *binop; 168 169 a = parse_prefix(parse); 170 while (lcur_lc(parse) == lc_plus) { 171 binop_class_t bc; 172 173 a = parse_multip(parse); 174 while (lcur_lc(parse) == lc_plus || lcur_lc(parse) == lc_minus) { 171 175 if (parse_is_error(parse)) 172 176 break; 173 177 178 switch (lcur_lc(parse)) { 179 case lc_plus: bc = bo_plus; break; 180 case lc_minus: bc = bo_minus; break; 181 default: assert(b_false); 182 } 183 174 184 lskip(parse); 175 b = parse_ prefix(parse);176 177 binop = stree_binop_new(b o_plus);185 b = parse_multip(parse); 186 187 binop = stree_binop_new(bc); 178 188 binop->arg1 = a; 179 189 binop->arg2 = b; … … 187 197 } 188 198 199 /** Parse multiplicative expression. 200 * 201 * @param parse Parser object. 202 */ 203 static stree_expr_t *parse_multip(parse_t *parse) 204 { 205 stree_expr_t *a, *b, *tmp; 206 stree_binop_t *binop; 207 binop_class_t bc; 208 209 a = parse_prefix(parse); 210 while (lcur_lc(parse) == lc_mult) { 211 if (parse_is_error(parse)) 212 break; 213 214 switch (lcur_lc(parse)) { 215 case lc_mult: bc = bo_mult; break; 216 default: assert(b_false); 217 } 218 219 lskip(parse); 220 b = parse_prefix(parse); 221 222 binop = stree_binop_new(bc); 223 binop->arg1 = a; 224 binop->arg2 = b; 225 226 tmp = stree_expr_new(ec_binop); 227 tmp->u.binop = binop; 228 a = tmp; 229 } 230 231 return a; 232 } 233 189 234 /** Parse prefix expression. 190 235 * … … 194 239 { 195 240 stree_expr_t *a; 241 stree_expr_t *tmp; 242 stree_unop_t *unop; 243 unop_class_t uc; 196 244 197 245 switch (lcur_lc(parse)) { 198 246 case lc_plus: 199 printf("Unimplemented: Unary plus.\n"); 200 a = parse_recovery_expr(parse); 201 parse_note_error(parse); 247 case lc_minus: 248 if (parse_is_error(parse)) 249 return parse_recovery_expr(parse); 250 251 switch (lcur_lc(parse)) { 252 case lc_plus: uc = uo_plus; break; 253 case lc_minus: uc = uo_minus; break; 254 default: assert(b_false); 255 } 256 257 lskip(parse); 258 a = parse_postfix(parse); 259 260 unop = stree_unop_new(uc); 261 unop->arg = a; 262 263 tmp = stree_expr_new(ec_unop); 264 tmp->u.unop = unop; 265 a = tmp; 202 266 break; 203 267 case lc_new: … … 248 312 stree_expr_t *tmp; 249 313 250 a = parse_p rimitive(parse);314 a = parse_paren(parse); 251 315 252 316 while (lcur_lc(parse) == lc_period || lcur_lc(parse) == lc_lparen || … … 398 462 } 399 463 464 /** Parse possibly partenthesized expression. 465 * 466 * @param parse Parser object. 467 */ 468 static stree_expr_t *parse_paren(parse_t *parse) 469 { 470 stree_expr_t *expr; 471 472 if (lcur_lc(parse) == lc_lparen) { 473 lskip(parse); 474 expr = parse_expr(parse); 475 lmatch(parse, lc_rparen); 476 } else { 477 expr = parse_primitive(parse); 478 } 479 480 return expr; 481 } 482 483 400 484 /** Parse primitive expression. 401 485 * … … 459 543 460 544 literal = stree_literal_new(ltc_int); 461 literal->u.lit_int.value = lcur(parse)->u.lit_int.value; 545 bigint_clone(&lcur(parse)->u.lit_int.value, 546 &literal->u.lit_int.value); 462 547 463 548 lskip(parse);
Note:
See TracChangeset
for help on using the changeset viewer.