lambda/parser.mly

33 lines
426 B
OCaml
Raw Normal View History

2018-02-13 23:43:40 +00:00
%{
open Types
%}
%token EOL
%token Dot
2018-02-16 11:22:07 +00:00
%token Equal
%token LParen
%token RParen
%token <string> Ident
2018-02-13 23:43:40 +00:00
%token Lambda
%start main
%type <Types.term> main
%%
main:
2018-02-16 11:22:07 +00:00
| assign EOL { $1 }
| expr EOL { $1 }
;
assign:
| Ident Equal expr { Types.Assign($1, $3) }
2018-02-13 23:43:40 +00:00
;
expr:
| var { Types.TmVar($1) }
| Lambda var Dot expr { Types.TmAbs($2, $4) }
2018-02-16 11:22:07 +00:00
| LParen expr expr RParen { Types.TmApp ($2, $3) }
2018-02-13 23:43:40 +00:00
;
var:
Ident { $1 }
;