-
Notifications
You must be signed in to change notification settings - Fork 9
/
expr.js.par
29 lines (24 loc) · 1.08 KB
/
expr.js.par
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
%!language javascript;
%whitespaces ' \t';
%lexeme int;
%default action [* @@ = @1 *];
%left '+' '-';
%left '*' '/';
calc$ : expr [* console.log("= %d", @expr);
@@ = @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.charCodeAt(0)
- '0'.charCodeAt(0) *]
| int '0-9' [* @@ = @int * 10 +
@2.charCodeAt(0)
- '0'.charCodeAt(0)
*]
;