| 338 |
return MINUS_EXPR; |
return MINUS_EXPR; |
| 339 |
else if(get_identifier("*") == t) |
else if(get_identifier("*") == t) |
| 340 |
return MULT_EXPR; |
return MULT_EXPR; |
| 341 |
|
else if(get_identifier("/") == t) |
| 342 |
|
return TRUNC_DIV_EXPR; |
| 343 |
|
else if(get_identifier("%") == t) |
| 344 |
|
return TRUNC_MOD_EXPR; |
| 345 |
else { |
else { |
| 346 |
fprintf(stderr, "Invalid operator : %s\n", IDENTIFIER_POINTER(t)); |
fprintf(stderr, "Invalid operator : %s\n", IDENTIFIER_POINTER(t)); |
| 347 |
gcc_unreachable(); |
gcc_unreachable(); |
| 383 |
* | Term |
* | Term |
| 384 |
* |
* |
| 385 |
* Term ::= Fact * Fact |
* Term ::= Fact * Fact |
| 386 |
|
* | Fact / Fact |
| 387 |
|
* | Fact % Fact |
| 388 |
* | Fact |
* | Fact |
| 389 |
* |
* |
| 390 |
* Fact ::= id '(' {Expr} (,Expr)* ')' // function call |
* Fact ::= id '(' {Expr} (,Expr)* ')' // function call |
| 391 |
* | '(' Expr ')' |
* | '(' Expr ')' |
| 392 |
* | id // variable |
* | id // variable |
| 393 |
* | integer |
* | integer |
| 394 |
|
* | ! Fact // not |
| 395 |
*/ |
*/ |
| 396 |
|
|
| 397 |
static tree parse_expr(void); |
static tree parse_expr(void); |
| 401 |
|
|
| 402 |
// function call : id '(' {Expr} (, Expr)* ')' |
// function call : id '(' {Expr} (, Expr)* ')' |
| 403 |
if(TREE_CODE(T1) == IDENTIFIER_NODE && |
if(TREE_CODE(T1) == IDENTIFIER_NODE && |
| 404 |
|
T1 != get_identifier("!") && |
| 405 |
check("(")) { |
check("(")) { |
| 406 |
tree fn_decl = lookup_variable(T1); |
tree fn_decl = lookup_variable(T1); |
| 407 |
if(TREE_CODE(fn_decl) != FUNCTION_DECL) { |
if(TREE_CODE(fn_decl) != FUNCTION_DECL) { |
| 423 |
return build_function_call_expr(fn_decl, args); |
return build_function_call_expr(fn_decl, args); |
| 424 |
} |
} |
| 425 |
|
|
| 426 |
if(T1 != get_identifier("(")) |
if(T1 == get_identifier("!")) { |
| 427 |
return eval_value(T1); |
tree exp = parse_fact(); |
| 428 |
|
return build1(BIT_NOT_EXPR,TREE_TYPE(exp),exp); |
| 429 |
|
} |
| 430 |
|
|
| 431 |
if(T1 == get_identifier("(")) { |
if(T1 == get_identifier("(")) { |
| 432 |
tree t = parse_expr(); |
tree t = parse_expr(); |
| 434 |
return t; |
return t; |
| 435 |
} |
} |
| 436 |
|
|
| 437 |
debug_tree(T1); |
return eval_value(T1); |
|
gcc_unreachable(); |
|
| 438 |
} |
} |
| 439 |
|
|
| 440 |
static tree parse_term(void) { |
static tree parse_term(void) { |
| 441 |
tree T1 = parse_fact(); |
tree T1 = parse_fact(); |
| 442 |
|
|
| 443 |
while(next_p()) { |
while(next_p()) { |
| 444 |
if(!check("*")) { |
if(!check("*") |
| 445 |
|
&& !check("/") |
| 446 |
|
&& !check("%")) { |
| 447 |
break; |
break; |
| 448 |
} |
} |
| 449 |
tree op = next(); |
tree op = next(); |