File: precedence.jison

package info (click to toggle)
node-jison 0.4.17%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 348 kB
  • ctags: 57
  • sloc: yacc: 32; makefile: 16; sh: 3
file content (32 lines) | stat: -rw-r--r-- 452 bytes parent folder | download | duplicates (3)
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
30
31
32

/* description: Grammar showing precedence operators and semantic actions. */

%lex
%%
\s+         {/* skip whitespace */}
[0-9]+         {return 'NAT';}
"+"         {return '+';}
"*"         {return '*';}
<<EOF>>         {return 'EOF';}

/lex

%left '+'
%left '*'

%%

S
    : e EOF
        {return $1;}
    ;

e
    : e '+' e
        {$$ = [$1,'+', $3];}
    | e '*' e
        {$$ = [$1, '*', $3];}
    | NAT
        {$$ = parseInt(yytext);}
    ;