read string first

This commit is contained in:
Michael Zhang 2018-02-20 05:49:46 -06:00
parent 2e46c8cacf
commit b1d92ca2ed
No known key found for this signature in database
GPG key ID: A1B65B603268116B
3 changed files with 17 additions and 10 deletions

View file

@ -23,6 +23,8 @@ clean:
rm -f lexer.ml parser.ml parser.mli rm -f lexer.ml parser.ml parser.mli
rm -f *.cmo *.cmi rm -f *.cmo *.cmi
all: types.cmo lexer.cmo parser.cmo lambda.cmo lambda: types.cmo lexer.cmo parser.cmo lambda.cmo
ocaml types.cmo parser.cmo lexer.cmo lambda.cmo ocamlc -o $@ $^
all: lambda

BIN
lambda Executable file

Binary file not shown.

View file

@ -82,14 +82,15 @@ let rec eval (ctx, t) =
if t = t' then raise EvaluationComplete else if t = t' then raise EvaluationComplete else
eval (ctx', t') eval (ctx', t')
with with
| UnboundVariable v -> print_endline ("unbound variable " ^ v); raise (Failure "") | UnboundVariable v -> raise (Failure ("unbound variable '" ^ v ^ "'"))
| EvaluationComplete -> (ctx, t) | EvaluationComplete -> (ctx, t)
let _ = let _ =
try let rec loop ctx =
let rec loop ctx = try
print_string "> "; flush stdout; 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 let x = Parser.main Lexer.token lexbuf in
match x with match x with
| Types.Term t -> | Types.Term t ->
@ -99,7 +100,11 @@ let _ =
| Types.Assign (n, t) -> | Types.Assign (n, t) ->
let (ctx', r) = eval (ctx, t) in let (ctx', r) = eval (ctx, t) in
loop (assign ctx' (n, r)) loop (assign ctx' (n, r))
in loop [] with
with Lexer.Eof -> | Lexer.Eof ->
print_endline "^D"; loop ctx
exit 0 | End_of_file ->
print_endline "^D";
exit 0
in loop []