Codebase list node-jison / upstream/0.4.17+dfsg examples / precedence.jison
upstream/0.4.17+dfsg

Tree @upstream/0.4.17+dfsg (Download .tar.gz)

precedence.jison @upstream/0.4.17+dfsgraw · history · blame

/* 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);}
    ;