45 lines
806 B
Plaintext
45 lines
806 B
Plaintext
%{
|
|
open Expr
|
|
%}
|
|
|
|
%token PLUS TIMES
|
|
%token TOP BOTTOM EXFALSO
|
|
%token LPAREN RPAREN
|
|
%token FUN ARR COLON
|
|
%token <string> VARID
|
|
%token <string> TYID
|
|
|
|
%token EOL
|
|
|
|
|
|
%left ARR
|
|
|
|
%start main
|
|
%type <Expr.expr> main
|
|
|
|
%%
|
|
main:
|
|
e=expression EOL { e }
|
|
|
|
ty_annot:
|
|
| id=VARID COLON t=ty { (id, t) }
|
|
|
|
ty:
|
|
| id=TYID { id }
|
|
| LPAREN t=ty RPAREN { ty }
|
|
| t1=ty ARR t2=ty {
|
|
|
|
expression:
|
|
| FUN LPAREN annot=ty_annot RPAREN ARR e=expression
|
|
{ Fun (annot, e) }
|
|
| e=app_expr { e }
|
|
|
|
app_expr:
|
|
| e=app_expr a=atomic { App (e, a) }
|
|
| a=atomic { a }
|
|
|
|
atomic:
|
|
| id=VARID { Var id }
|
|
| LPAREN e=expression RPAREN
|
|
{ e }
|