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 open Parser
} }
rule token = parse rule token_ty = parse
(* Sauter les espaces et les tabulations *) | [' ' '\t' '\n'] { token_ty lexbuf }
| [' ' '\t' '\n'] { token lexbuf } | eof { EOF }
| '(' { LPAREN } | '(' { LPAREN }
| ')' { RPAREN } | ')' { RPAREN }
| "->" { RARROW } | "->" { RARROW }
| '~' { TILDE } | '~' { TILDE }
| "False" { FALSE } | "False" { FALSE }
| ['a'-'z']+['0'-'9']* as s { VAR_NAME s }
| ['A'-'Z']+['0'-'9']* as s { TYPE_NAME s } | ['A'-'Z']+['0'-'9']* as s { TYPE_NAME s }
and token_tactic = parse
| [' ' '\t' '\n'] { token_tactic lexbuf }
| eof { EOF } | 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 = let ty =
try try
let lexbuf = Lexing.from_string (readline ()) in let lexbuf = Lexing.from_string (readline ()) in
Parser.main_type Lexer.token lexbuf Parser.main_type Lexer.token_ty lexbuf
with e -> ( with e -> (
Printf.printf "Can't parse type\n"; Printf.printf "Can't parse type\n";
raise e raise e
@ -66,7 +66,21 @@ while true do
(* Lecture d'une tactique *) (* Lecture d'une tactique *)
Printf.printf "What do you want to do?\n"; 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; done;

View File

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

View File

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