-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexpr.c.par
More file actions
23 lines (18 loc) · 714 Bytes
/
expr.c.par
File metadata and controls
23 lines (18 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
%!language C;
%whitespaces ' \t';
%lexeme int;
%default action [* @@ = @1 *];
%left '+' '-';
%left '*' '/';
calc$ : expr [* printf( "= %d\n", @expr ) *]
;
expr : expr:a '+' expr:b [* @@ = @a + @b *]
| expr:a '-' expr:b [* @@ = @a - @b *]
| expr:a '*' expr:b [* @@ = @a * @b *]
| expr:a '/' expr:b [* @@ = @a / @b *]
| '(' expr ')' [* @@ = @expr *]
| int
;
int : '0-9' [* @@ = @1 - '0' *]
| int '0-9' [* @@ = @int * 10 + @2 - '0' *]
;