Skip to content

Instantly share code, notes, and snippets.

@hakobe
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakobe/3f4676683fdd8c3674c5 to your computer and use it in GitHub Desktop.
Save hakobe/3f4676683fdd8c3674c5 to your computer and use it in GitHub Desktop.
%lex
%%
\s+ /* skip whitespace */
"fun" return 'FUN'
[0-9]+ return 'INT'
"=>" return '=>'
<<EOF>> return 'EOF'
. return 'INVALID'
/lex
%nonassoc FUNEXP
%left APPLY
%start expressions
%%
expressions
: e EOF
{ return $1; }
;
e
: e e %prec APPLY
{$$ = ['APPLY', $1, $2];}
| FUN var '=>' e %prec FUNEXP
{$$ = ['FUN', $2, $4];}
;
Conflict in grammar: multiple actions possible when lookahead token is FUN in state 5
- reduce by rule: e -> e e
- shift token (then go to state 3)
Conflict in grammar: multiple actions possible when lookahead token is FUN in state 8
- reduce by rule: e -> FUN var => e
- shift token (then go to state 3)
States with conflicts:
State 5
e -> e e . #lookaheads= EOF FUN
e -> e .e
e -> .e e
e -> .FUN var => e
State 8
e -> FUN var => e . #lookaheads= EOF FUN
e -> e .e
e -> .e e
e -> .FUN var => e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment