Commit 90028212 authored by Julien Lopez's avatar Julien Lopez
Browse files

[TESTS][EVAL] letexpr added; externals dependencies solved, remains to merge

	local and external lambda files
parent 6d8da9d8
......@@ -5,6 +5,9 @@ expr = id
| expr "," expr
| "(" expr ")"
| "match" expr "with" "|" expr ["&" type_id] "->" expr branches
| "let" id "=" expr (* TODO *)
| "let" id "=" expr "in" expr
| expr ";;" expr (* TODO *)
abstr = "fun" id params "->" expr
......
......@@ -6,7 +6,14 @@ EXTDIR ?= $(SRCDIR)/externals
INEXTFILES = misc/custom.ml misc/encodings.ml types/ident.ml\
compile/lambda.mli compile/lambda.ml misc/ns.ml misc/ns.mli misc/upool.ml\
misc/upool.mli types/sortedList.ml types/sortedList.mli types/compunit.ml\
types/compunit.mli types/types.mli types/types.ml runtime/eval.ml
types/compunit.mli types/types.mli types/types.ml runtime/eval.mli\
runtime/eval.ml types/boolVar.ml types/var.ml types/atoms.ml misc/imap.ml\
types/intervals.ml types/chars.ml misc/bool.ml compile/auto_pat.ml\
runtime/value.ml types/sequence.ml schema/schema_validator.ml\
schema/schema_pcre.ml schema/schema_common.ml schema/schema_common.mli\
schema/schema_types.ml schema/schema_xml.ml schema/schema_xml.mli\
schema/schema_builtin.ml types/builtin_defs.ml runtime/run_dispatch.ml\
runtime/explain.ml
EXTFILES = $(INEXTFILES:%=$(ROOTDIR)/%)
RM ?= rm -f
......
......@@ -3,3 +3,4 @@
<src/main*>: pp(camlp4orf.opt), package(camlp4.lib)
<src/externals>: include
<src/externals/schema_*>: package(pcre, netcgi2)
......@@ -6,7 +6,8 @@ type expr =
| Var of string
| Int of int
| Pair of expr * expr
| Match of expr * (expr * string option * expr) list;;
| Match of expr * (expr * string option * expr) list
| Let of string * expr * expr;;
module ExprParser = struct
open Camlp4.PreCast
......@@ -20,7 +21,10 @@ module ExprParser = struct
expression:
[
"abstr" RIGHTA
"letexpr"
[ "let"; x = LIDENT; "="; e1 = expression; "in"; e2 = expression ->
Let(x, e1, e2)]
| "abstr" RIGHTA
[ "fun"; x = LIDENT; p = LIST0 param; "->"; e = expression ->
Abstract(x, p, e)
| "match"; e1 = expression; "with"; b = LIST1 branch -> Match(e1, b) ]
......@@ -64,6 +68,8 @@ let rec print_expr expr = match expr with
printf ")"
| Match(e, b) -> printf "Match("; print_expr e; printf ", ";
print_branches b; printf ")"
| Let(x, e1, e2) -> printf "Let(%s, " x; print_expr e1; printf ", ";
print_expr e2; printf ")"
and print_params params = match params with
| p :: rest -> printf " %s" p; print_params rest
......@@ -86,6 +92,8 @@ let rec expr_to_string expr = match expr with
^ ")"
| Match(e, b) -> "match " ^ (expr_to_string e) ^ " with"
^ (branches_to_string b)
| Let(x, e1, e2) -> "let " ^ x ^ " = " ^ (expr_to_string e1) ^ " in "
^ (expr_to_string e2)
and params_to_string params = match params with
| p :: rest -> " " ^ p ^ (params_to_string rest)
......
......@@ -10,9 +10,9 @@ let load_file f =
s;;
let str = if Array.length Sys.argv > 1 then load_file Sys.argv.(1)
else "fun firsts x y -> match x,y with
else "let z = 3 in fun firsts x y -> match x,y with
| (a,_),(b,_) -> a,b (* This (* is (* a nested *) *) comment *)
| _ -> x (* That doesn't make any sense *)" in
| _ -> x . z (* That doesn't make any sense *)" in
let expr = ExprParser.of_string str in
printf "Original: %s\nExpr: " str;
print_expr expr;
......
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