Commit 1d56b204 authored by Aliaume Lopez's avatar Aliaume Lopez

Add the let binding syntax

parent a9f4570e
......@@ -174,8 +174,29 @@ let circuit_of_name = function
* variable of the grammar is just converted into a
* recursive function that parses (because the grammar is LL)
*
* Bon, il faut gérer l'AST, la structure de sortie c'est
*
* [String * AST] * AST
*
* Et ensuite faire le remplacement textuel,
*
*
*)
let rec parse_parallel s i = (* P *)
let rec parse_let s i =
let combine circ_name circ_def (dict,circ) =
((circ_name,circ_def) :: dict, circ)
in
begin
(pure combine <*>
begin
parse_sstring "let" <*>> parse_circ_name <<*> parse_sstring "="
end
<*> parse_parallel <*> (parse_sstring "in" <*>> parse_let)) <|>
(pure (fun x -> ([], x)) <*> parse_parallel)
end s i
and parse_parallel s i = (* P *)
begin
pure (|||) <*> parse_sequential <*> parse_parallel_rec
end s i
......@@ -262,6 +283,19 @@ let parse_ast s = match parse_parallel s 0 with
| Some (x,k) -> x;;
let parse_eval s = match parse_let s 0 with
| None -> failwith "parsing failed"
| Some ((dict,ast),k) ->
let dict = List.rev dict in
let apply_func ast (key, value) =
foldc (function
| Const (x,_,_) when key = x -> value
| x -> Circ x)
ast
in
List.fold_left apply_func ast dict;;
(******* TESTS DE PARSING ********)
let test1 = "F";;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment