pieuvre/parser.mly
2024-05-17 08:10:26 +02:00

90 lines
2.2 KiB
OCaml

%{
open Lam
open Types
open Proof
open Parser_entry
%}
%token EOF
%token DOT COMMA
%token PLUS TIMES
%token TOP BOT EXFALSO TILDE
%token LPAREN RPAREN
%token FUN ARR COLON TARR
%token AND OR
%token <string> VARID
%token <string> TYID
%token GOAL UNDO QED
%token EXACT ASSUMPTION INTRO INTROS CUT APPLY
%token LEFT RIGHT SPLIT DESTRUCT
%token L R
%right TARR
%right OR
%right AND
%right TILDE
%start main
%type <parser_entry> main
%%
main:
| e=expression EOF { Lam e }
| ts=nonempty_list(tactic) EOF { Cmd ts }
tactic:
| c=command DOT { c }
command:
| GOAL t=ty { Goal t }
| UNDO { Undo }
| QED { Qed }
| EXACT e=expression { Tact (Exact_term e) }
| EXACT s=TYID { Tact (Exact_proof s) }
| ASSUMPTION { Tact (Assumption) }
| INTROS { Tact (Intros) }
| INTRO { Tact (Intro) }
| SPLIT { Tact (Split) }
| RIGHT { Tact (Right) }
| LEFT { Tact (Left) }
| CUT t=ty { Tact (Cut t) }
| APPLY s=TYID { Tact (Apply s) }
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 AND t2=ty { And(t1, t2) }
| t1=ty OR t2=ty { Or(t1, t2) }
| 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) }
| LPAREN e1=expression COMMA e2=expression RPAREN
{ Pair(e1, e2) }
| L LPAREN e=expression COLON t=ty RPAREN
{ Left(e, t) }
| R LPAREN e=expression COLON t=ty RPAREN
{ Right(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 }