support / (div),% (mod),! (not) operator
| @@ -338,6 +338,10 @@ | ||
| 338 | 338 | return MINUS_EXPR; |
| 339 | 339 | else if(get_identifier("*") == t) |
| 340 | 340 | 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; | |
| 341 | 345 | else { |
| 342 | 346 | fprintf(stderr, "Invalid operator : %s\n", IDENTIFIER_POINTER(t)); |
| 343 | 347 | gcc_unreachable(); |
| @@ -379,6 +383,8 @@ | ||
| 379 | 383 | * | Term |
| 380 | 384 | * |
| 381 | 385 | * Term ::= Fact * Fact |
| 386 | + * | Fact / Fact | |
| 387 | + * | Fact % Fact | |
| 382 | 388 | * | Fact |
| 383 | 389 | * |
| 384 | 390 | * Fact ::= id '(' {Expr} (,Expr)* ')' // function call |
| @@ -385,6 +391,7 @@ | ||
| 385 | 391 | * | '(' Expr ')' |
| 386 | 392 | * | id // variable |
| 387 | 393 | * | integer |
| 394 | + * | ! Fact // not | |
| 388 | 395 | */ |
| 389 | 396 | |
| 390 | 397 | static tree parse_expr(void); |
| @@ -394,6 +401,7 @@ | ||
| 394 | 401 | |
| 395 | 402 | // function call : id '(' {Expr} (, Expr)* ')' |
| 396 | 403 | if(TREE_CODE(T1) == IDENTIFIER_NODE && |
| 404 | + T1 != get_identifier("!") && | |
| 397 | 405 | check("(")) { |
| 398 | 406 | tree fn_decl = lookup_variable(T1); |
| 399 | 407 | if(TREE_CODE(fn_decl) != FUNCTION_DECL) { |
| @@ -415,8 +423,10 @@ | ||
| 415 | 423 | return build_function_call_expr(fn_decl, args); |
| 416 | 424 | } |
| 417 | 425 | |
| 418 | - if(T1 != get_identifier("(")) | |
| 419 | - return eval_value(T1); | |
| 426 | + if(T1 == get_identifier("!")) { | |
| 427 | + tree exp = parse_fact(); | |
| 428 | + return build1(BIT_NOT_EXPR,TREE_TYPE(exp),exp); | |
| 429 | + } | |
| 420 | 430 | |
| 421 | 431 | if(T1 == get_identifier("(")) { |
| 422 | 432 | tree t = parse_expr(); |
| @@ -424,8 +434,7 @@ | ||
| 424 | 434 | return t; |
| 425 | 435 | } |
| 426 | 436 | |
| 427 | - debug_tree(T1); | |
| 428 | - gcc_unreachable(); | |
| 437 | + return eval_value(T1); | |
| 429 | 438 | } |
| 430 | 439 | |
| 431 | 440 | static tree parse_term(void) { |
| @@ -432,7 +441,9 @@ | ||
| 432 | 441 | tree T1 = parse_fact(); |
| 433 | 442 | |
| 434 | 443 | while(next_p()) { |
| 435 | - if(!check("*")) { | |
| 444 | + if(!check("*") | |
| 445 | + && !check("/") | |
| 446 | + && !check("%")) { | |
| 436 | 447 | break; |
| 437 | 448 | } |
| 438 | 449 | tree op = next(); |