Parse tactics

This commit is contained in:
Adrien Vannson 2022-05-08 20:03:29 +02:00
parent f833807253
commit fc7317b2d0
No known key found for this signature in database
GPG Key ID: FE2E66FD978C1A55
4 changed files with 48 additions and 16 deletions

View File

@ -2,14 +2,20 @@
open Parser
}
rule token = parse
(* Sauter les espaces et les tabulations *)
| [' ' '\t' '\n'] { token lexbuf }
rule token_ty = parse
| [' ' '\t' '\n'] { token_ty lexbuf }
| eof { EOF }
| '(' { LPAREN }
| ')' { RPAREN }
| "->" { RARROW }
| '~' { TILDE }
| "False" { FALSE }
| ['a'-'z']+['0'-'9']* as s { VAR_NAME s }
| ['A'-'Z']+['0'-'9']* as s { TYPE_NAME s }
and token_tactic = parse
| [' ' '\t' '\n'] { token_tactic lexbuf }
| eof { EOF }
| "intro" { INTRO }
| ['a'-'z']+['0'-'9']* as s { VAR_NAME s }
| '.' { DOT }

18
main.ml
View File

@ -45,7 +45,7 @@ show "Please type the formula to prove\n";
let ty =
try
let lexbuf = Lexing.from_string (readline ()) in
Parser.main_type Lexer.token lexbuf
Parser.main_type Lexer.token_ty lexbuf
with e -> (
Printf.printf "Can't parse type\n";
raise e
@ -66,7 +66,21 @@ while true do
(* Lecture d'une tactique *)
Printf.printf "What do you want to do?\n";
let line = read_line () in
let tactic =
let rec read_tactic () =
try
let lexbuf = Lexing.from_string (readline ()) in
Parser.main_tactic Lexer.token_tactic lexbuf
with e -> (
Printf.printf "Can't parse tactic\n";
if is_interactive then
read_tactic ()
else
raise e
)
in
read_tactic ()
in
()
)
done;

View File

@ -1,12 +1,16 @@
%{
open Structs;;
open Tactic;;
%}
/* Description des lexèmes définis dans lexer.mll */
%token LPAREN RPAREN RARROW TILDE FALSE
%token EOF
%token <string> VAR_NAME
%token <string> TYPE_NAME
%token ENDL EOF
%token DOT INTRO
/* L'ordre de définition définit la priorité */
%left RARROW
@ -15,9 +19,10 @@
%start main_type
%type <Structs.ty> main_type
/* Définition des règles de grammaire */
%%
%start main_tactic
%type <Tactic.tactic> main_tactic
%%
main_type:
| ty EOF { $1 }
@ -27,3 +32,9 @@ ty:
| TYPE_NAME { TSimple $1 }
| TILDE ty { TImpl ($2, TFalse) }
| FALSE { TFalse }
main_tactic:
| tactic EOF { $1 }
tactic:
| INTRO VAR_NAME DOT { Intro $2 }

View File

@ -1,28 +1,29 @@
(* Variables des λ-termes *)
type var = string;;
type var_lambda = string;;
type var = var_lambda;; (* TODEL *)
let varRegex = Str.regexp "^([a-z]+)([0-9]*)$";;
(* Variable des types simples *)
type type_var = string;;
type tvar = type_var;; (* TODEL *)
type var_type = string;;
type tvar = var_type;; (* TODEL *)
let tvarRegex = Str.regexp "^([A-Z]+)([0-9]*)$";;
(* Type complexe *)
type ty =
| TSimple of type_var
| TSimple of var_type
| TImpl of ty * ty
| TFalse;;
(* λ-terme *)
type lam =
| LFun of var * ty * lam
| LFun of var_lambda * ty * lam
| LApp of lam * lam
| LVar of var
| LVar of var_lambda
| LExf of lam * ty;;
(* Environnement de typage *)
type gam = (type_var * ty) list;;
type gam = (var_type * ty) list;;
(* λ-terme avec des trous *)
type lho = (lam list) -> lam;;