-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
open Cish_ast | ||
open Cish_eval | ||
|
||
(* This magic is used to glue the generated lexer and parser together. | ||
* Expect one command-line argument, a file to parse. | ||
* You do not need to understand this interaction with the system. *) | ||
let parse_file() = | ||
let argv = Sys.argv in | ||
let _ = | ||
if Array.length argv != 2 | ||
then (prerr_string ("usage: " ^ argv.(0) ^ " [file-to-parse]\n"); | ||
exit 1) in | ||
let ch = open_in argv.(1) in | ||
Cish_parse.program Cish_lex.lexer (Lexing.from_channel ch) | ||
|
||
let parse_stdin() = | ||
Cish_parse.program Cish_lex.lexer (Lexing.from_channel stdin) | ||
|
||
let compile_prog prog = | ||
Cish_compile.result2string (Cish_compile.compile prog ) | ||
|
||
(* Reads in cish code and evaluates it *) | ||
let _ = | ||
let prog = parse_stdin() in | ||
let ans = eval prog in | ||
print_string ("answer = "^(val2string ans)^"\n") | ||
(* print_string (compile_prog prog) *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
open Scish_ast | ||
open Scish_eval | ||
|
||
(* This magic is used to glue the generated lexer and parser together. | ||
* Expect one command-line argument, a file to parse. | ||
* You do not need to understand this interaction with the system. *) | ||
let parse_file () = | ||
let argv = Sys.argv in | ||
let _ = | ||
if Array.length argv != 2 | ||
then (prerr_string ("usage: " ^ argv.(0) ^ " [file-to-parse]\n"); | ||
exit 1) in | ||
let ch = open_in argv.(1) in | ||
Scish_parse.program Scish_lex.lexer (Lexing.from_channel ch) | ||
|
||
let parse_stdin () = | ||
Scish_parse.program Scish_lex.lexer (Lexing.from_channel stdin) | ||
|
||
let compile_prog prog = Scish_compile.compile_exp prog | ||
|
||
let run_prog prog = Scish_eval.run prog | ||
|
||
let dump p = print_string (Cish_ast.prog2string p) | ||
|
||
let _ = | ||
let prog = parse_stdin() in | ||
(* | ||
let _ = print_string ("answer = "^(string_of_int ans)^"\n") in | ||
*) | ||
|
||
dump (compile_prog prog) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
((lambda (x) (if (< x 5) (* x 5) (* x 2))) 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(+ 5 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(fst (cons 5 4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(((lambda (x) (lambda (x) (+ x x))) 42) 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
((lambda (x) (* x x)) 5) |