pieuvre/parser.mly
2024-04-16 10:07:09 +02:00

50 lines
1.0 KiB
OCaml

%{
open Lam
open Types
%}
%token PLUS TIMES
%token TOP BOT EXFALSO TILDE
%token LPAREN RPAREN
%token FUN ARR COLON TARR
%token <string> VARID
%token <string> TYID
%token EOL
%right TARR
%right TILDE
%start main
%type <Lam.lam> main
%%
main:
e=expression EOL { e }
ty_annot:
| id=VARID COLON t=ty { (id, t) }
ty:
| id=TYID { TVar(id) }
| BOT { Bot }
| LPAREN t=ty RPAREN { t }
| TILDE t=ty { Arr(t, Bot) }
| t1=ty TARR t2=ty { Arr(t1, t2) }
expression:
| FUN LPAREN annot=ty_annot RPAREN ARR e=expression
{ Fun (annot, e) }
| EXFALSO LPAREN e=expression COLON t=ty RPAREN
{ Exf (e, t) }
| 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 }