added basic parser

master
Rachel Lambda Samuelsson 2022-09-03 11:06:12 +02:00
parent 9115694545
commit 963015801e
8 changed files with 75 additions and 2 deletions

View File

@ -39,6 +39,7 @@ let rec eval (env : V.env) (tr : T.term) =
| Pair (x, y) -> V.Pair (eval env x, eval env y)
| Fst tr -> fst (eval env tr)
| Snd tr -> snd (eval env tr)
| Let (tr, _, B sc) -> eval (eval env tr :: env) sc
(* B b, B B ts *)
and indN (env : V.env) (b : T.term) (tz : V.value) (ts : T.term) (n : V.value) =

View File

@ -31,3 +31,5 @@ type term
| Pair of term * term
| Fst of term
| Snd of term
| Let of term * term * term binder (* tr : ty in sc *)

2
lib/Core/dune 100644
View File

@ -0,0 +1,2 @@
(library
(name Core))

10
lib/Parse/dune 100644
View File

@ -0,0 +1,10 @@
(library
(name Parse)
(flags (:standard -w -27 -w -39 -w -33)))
(rule
(alias bnfc)
(deps "implicitt.cf")
(targets AbsImplicitt.ml BNFC_Util.ml LexImplicitt.mll ParImplicitt.mly PrintImplicitt.ml ShowImplicitt.ml SkelImplicitt.ml TestImplicitt.ml)
(action (system "bnfc --ocaml implicitt.cf")))
(ocamllex LexImplicitt)
(ocamlyacc ParImplicitt)

View File

@ -0,0 +1,60 @@
entrypoints [Def], Term;
token Id ((letter|digit|["[]_"])+) ;
comment "--" ;
comment "{-" "-}" ;
Defn. Def ::= "def" Id ":" Term ":=" Term;
separator nonempty Def "" ;
-- names bound by lambdas
NImp. Name ::= "{" Id "}";
NExp. Name ::= Id;
separator nonempty Name "" ;
-- Term 2
TVar. Term2 ::= Id;
TType. Term2 ::= "Type";
TT0. Term2 ::= "𝟘";
TT1. Term2 ::= "𝟙";
TT1tr. Term2 ::= "";
TBool. Term2 ::= "𝟚";
TTrue. Term2 ::= "true";
TFalse. Term2 ::= "false";
TNat. Term2 ::= "";
TZero. Term2 ::= "0";
TLam. Term2 ::= "λ" [Name] "." Term;
-- Term1
TInd0. Term1 ::= "𝟘-elim" Term2 Term2;
TIndB. Term1 ::= "𝟚-elim" Term2 Term2 Term2 Term2;
TSuc. Term1 ::= "suc" Term2;
TIndN. Term1 ::= "-elim" Term2 Term2 Term2 Term2;
TFst. Term1 ::= "pr" Term2;
TSnd. Term1 ::= "pr" Term2;
TApp. Term1 ::= Term1 Term2;
-- Term0
TLet. Term ::= "let" Id ":" Term ":=" Term "in" Term ;
TPiAr. Term ::= Term "" Term;
TPiEx. Term ::= "(" Id ":" Term ")" "" Term;
TPiIm. Term ::= "{" Id ":" Term "}" "" Term;
TSgCr. Term ::= Term "×" Term;
TSg. Term ::= "(" Id ":" Term ")" "×" Term;
TPair. Term ::= "" Term "," Term "";
coercions Term 2;

View File

@ -1,2 +0,0 @@
(library
(name implicitt))