diff --git a/Makefile b/Makefile index 0e2a1cd..8df607f 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,8 @@ clean: rm -f lexer.ml parser.ml parser.mli rm -f *.cmo *.cmi -all: types.cmo lexer.cmo parser.cmo lambda.cmo - ocaml types.cmo parser.cmo lexer.cmo lambda.cmo +lambda: types.cmo lexer.cmo parser.cmo lambda.cmo + ocamlc -o $@ $^ + +all: lambda diff --git a/lambda b/lambda new file mode 100755 index 0000000..8badaf7 Binary files /dev/null and b/lambda differ diff --git a/lambda.ml b/lambda.ml index 3655348..137be98 100644 --- a/lambda.ml +++ b/lambda.ml @@ -82,14 +82,15 @@ let rec eval (ctx, t) = if t = t' then raise EvaluationComplete else eval (ctx', t') with - | UnboundVariable v -> print_endline ("unbound variable " ^ v); raise (Failure "") + | UnboundVariable v -> raise (Failure ("unbound variable '" ^ v ^ "'")) | EvaluationComplete -> (ctx, t) let _ = - try - let rec loop ctx = + let rec loop ctx = + try print_string "> "; flush stdout; - let lexbuf = Lexing.from_channel stdin in + let line = input_line stdin in + let lexbuf = Lexing.from_string line in let x = Parser.main Lexer.token lexbuf in match x with | Types.Term t -> @@ -99,7 +100,11 @@ let _ = | Types.Assign (n, t) -> let (ctx', r) = eval (ctx, t) in loop (assign ctx' (n, r)) - in loop [] - with Lexer.Eof -> - print_endline "^D"; - exit 0 + with + | Lexer.Eof -> + loop ctx + | End_of_file -> + print_endline "^D"; + exit 0 + in loop [] +