pieuvre/parser.mly

45 lines
832 B
OCaml
Raw Normal View History

2024-04-09 11:09:33 +02:00
%{
open Expr
2024-04-15 12:07:49 +02:00
open Types
2024-04-09 11:09:33 +02:00
%}
%token PLUS TIMES
%token TOP BOTTOM EXFALSO
%token LPAREN RPAREN
%token FUN ARR COLON
%token <string> VARID
%token <string> TYID
%token EOL
2024-04-15 12:07:49 +02:00
%right ARR
2024-04-09 11:09:33 +02:00
%start main
%type <Expr.expr> main
%%
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) }
| LPAREN t=ty RPAREN { t }
| t1=ty ARR t2=ty { Arr(t1, t2) }
2024-04-09 11:09:33 +02:00
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 }