Procedures in interpretation

This commit is contained in:
Dmitry Boulytchev 2018-03-27 01:51:22 +03:00
parent 30697f19eb
commit b4ef95c8bc
22 changed files with 337 additions and 188 deletions

View file

@ -6,7 +6,7 @@ let parse infile =
(object
inherit Matcher.t s
inherit Util.Lexers.decimal s
inherit Util.Lexers.ident ["read"; "write"; "skip"; "if"; "then"; "else"; "elif"; "fi"; "while"; "do"; "od"; "repeat"; "until"; "for"] s
inherit Util.Lexers.ident ["read"; "write"; "skip"; "if"; "then"; "else"; "elif"; "fi"; "while"; "do"; "od"; "repeat"; "until"; "for"; "fun"; "local"] s
inherit Util.Lexers.skip [
Matcher.Skip.whitespaces " \t\n";
Matcher.Skip.lineComment "--";
@ -25,9 +25,11 @@ let main =
match parse infile with
| `Ok prog ->
if to_compile
then
then failwith "Not implemented yet"
(*
let basename = Filename.chop_suffix infile ".expr" in
ignore @@ X86.build prog basename
*)
else
let rec read acc =
try
@ -40,7 +42,7 @@ let main =
let output =
if interpret
then Language.eval prog input
else SM.run (SM.compile prog) input
else failwith "Not implemented yet" (*SM.run (SM.compile prog) input*)
in
List.iter (fun i -> Printf.printf "%d\n" i) output
| `Fail er -> Printf.eprintf "Syntax error: %s\n" er