pieuvre/parser.mly

50 lines
1.0 KiB
OCaml
Raw Normal View History

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