some cosmetic changes+fix in calculator
This commit is contained in:
parent
4359c699dc
commit
57b1a2757e
1 changed files with 13 additions and 14 deletions
|
@ -896,11 +896,7 @@ stat { int ident, val; } :
|
||||||
;
|
;
|
||||||
|
|
||||||
expr(int level, *val;) { int expr; } :
|
expr(int level, *val;) { int expr; } :
|
||||||
%if (level <= MAXPRIO)
|
factor(val)
|
||||||
/* The grammar is ambiguous here. If level > MAXPRIO,
|
|
||||||
* this invocation will only scan one factor
|
|
||||||
*/
|
|
||||||
expr(MAXPRIO+1,val)
|
|
||||||
[ %while (prio(tok.t_tokno) >= level)
|
[ %while (prio(tok.t_tokno) >= level)
|
||||||
/* Swallow operators as long as their priority is
|
/* Swallow operators as long as their priority is
|
||||||
* larger than or equal to the level of this invocation
|
* larger than or equal to the level of this invocation
|
||||||
|
@ -911,21 +907,24 @@ expr(int level, *val;) { int expr; } :
|
||||||
* should group right to left, the rule should read:
|
* should group right to left, the rule should read:
|
||||||
* '+' expr(prio('+'),&expr)
|
* '+' expr(prio('+'),&expr)
|
||||||
*/
|
*/
|
||||||
| '-' expr(prio('-'),&expr)
|
| '-' expr(prio('-')+1,&expr)
|
||||||
{ *val -= expr; }
|
{ *val -= expr; }
|
||||||
| '*' expr(prio('*'),&expr)
|
| '*' expr(prio('*')+1,&expr)
|
||||||
{ *val *= expr; }
|
{ *val *= expr; }
|
||||||
| '/' expr(prio('/'),&expr)
|
| '/' expr(prio('/')+1,&expr)
|
||||||
{ *val /= expr; }
|
{ *val /= expr; }
|
||||||
| '%' expr(prio('%'),&expr)
|
| '%' expr(prio('%')+1,&expr)
|
||||||
{ *val %= expr; }
|
{ *val %= expr; }
|
||||||
| '&' expr(prio('&'),&expr)
|
| '&' expr(prio('&')+1,&expr)
|
||||||
{ *val &= expr; }
|
{ *val &= expr; }
|
||||||
| '|' expr(prio('|'),&expr)
|
| '|' expr(prio('|')+1,&expr)
|
||||||
{ *val |= expr; }
|
{ *val |= expr; }
|
||||||
]*
|
]*
|
||||||
/* Notice the "*" here. It is important.
|
/* Notice the "*" here. It is important.
|
||||||
*/
|
*/
|
||||||
|
;
|
||||||
|
|
||||||
|
factor(int *val;):
|
||||||
| '(' expr(1,val) ')'
|
| '(' expr(1,val) ')'
|
||||||
| '-' expr(MAXPRIO+1,val)
|
| '-' expr(MAXPRIO+1,val)
|
||||||
{ *val = -*val; }
|
{ *val = -*val; }
|
||||||
|
|
Loading…
Reference in a new issue