-
Notifications
You must be signed in to change notification settings - Fork 6
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
Berke Durak
committed
Dec 13, 2007
1 parent
d0531ad
commit c44c8c4
Showing
11 changed files
with
155 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
|
||
all: | ||
@ocamlbuild astsaver.native | ||
|
||
clean: | ||
@rm -rf _build _log astsaver.native |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
.PHONY: all | ||
.PHONY: all clean | ||
|
||
all: | ||
@ocamlbuild test_arith.native | ||
@ocamlbuild calculator.native | ||
|
||
clean: | ||
@rm -rf _build _log calculator.native |
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 |
---|---|---|
@@ -1 +1 @@ | ||
<test_arith.{byte,native}>: use_aurochs_lib, use_libaurochs, use_unix | ||
<calculator.{byte,native}>: use_aurochs_lib, use_libaurochs, use_unix |
File renamed without changes.
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
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,7 @@ | ||
.PHONY: all clean | ||
|
||
all: | ||
@ocamlbuild simplecalc.native | ||
|
||
clean: | ||
@rm -rf _build _log |
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 @@ | ||
<simplecalc.{byte,native}>: use_aurochs_lib, use_libaurochs, use_unix |
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,43 @@ | ||
(* Ocamlbuild plugin *) | ||
|
||
open Ocamlbuild_pack;; | ||
open Ocamlbuild_plugin;; | ||
open Command;; | ||
open Ocaml_specific;; | ||
open Outcome;; | ||
|
||
let aurochs = ref (S[A"aurochs";A"-target";A"ml";A"-generate"]);; | ||
let system_lib_dir = "/usr/lib";; | ||
|
||
dispatch | ||
begin function | ||
| After_rules -> | ||
begin | ||
List.iter | ||
begin fun dir -> | ||
flag ["ocaml"; "link"] (S[A"-I"; A dir]); | ||
flag ["ocaml"; "compile"] (S[A"-I"; A dir]); | ||
flag ["ocaml"; "doc"] (S[A"-I"; A dir]) | ||
end | ||
["+aurochs_lib"]; | ||
|
||
ocaml_lib ~extern:true "aurochs_lib"; | ||
|
||
flag ["link"; "ocaml"; "byte"; "use_libaurochs"] | ||
(S[A"-dllib";A("-laurochs"); A"-cclib";A("-laurochs")]); | ||
|
||
flag ["link"; "ocaml"; "use_libaurochs"] | ||
(S[A"-ccopt"; A("-L"^system_lib_dir); A"-cclib"; A"-laurochs"]); | ||
|
||
rule "aurochs: .peg -> .ml,.mli" | ||
~prods:["%.ml";"%.mli"] | ||
~dep:"%.peg" | ||
begin fun env _build -> | ||
let peg = env "%.peg" and ml = env "%.ml" in | ||
let tags = tags_of_pathname ml++"aurochs" in | ||
Cmd(S[!aurochs; T tags; P peg]) | ||
end | ||
end | ||
| _ -> () | ||
end | ||
;; |
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,35 @@ | ||
(* Test_arith *) | ||
|
||
open Aurochs_pack | ||
open Peg | ||
|
||
let _ = | ||
let grammar =" | ||
int ::= <num>val:[0-9]+</num>; | ||
outfixing [ \\n\\t]* do | ||
start ::= sum EOF; | ||
sum ::= <add> term '+' sum </add> | term; | ||
term ::= <mul> simple '*' term </mul> | simple; | ||
simple ::= int | '(' sum ')'; | ||
done;" | ||
in | ||
let rec eval = function | ||
| Node("root", _, [x]) -> eval x | ||
| Node("add", _, [x;y]) -> (eval x) + (eval y) | ||
| Node("mul", _, [x;y]) -> (eval x) * (eval y) | ||
| Node("sub", _, [x;y]) -> (eval x) - (eval y) | ||
| Node("neg", _, [x]) -> - (eval x) | ||
| Node("num", ["val",x], []) -> int_of_string x | ||
| _ -> assert false | ||
in | ||
while true do | ||
Printf.printf "> %!"; | ||
let u = input_line stdin in | ||
try | ||
let t = Aurochs.see ~grammar:(`Source(`String grammar)) ~text:(`String u) in | ||
let x = eval t in | ||
Printf.printf "%d\n%!" x; | ||
with | ||
| x -> | ||
Printf.printf "Exception: %s\n%!" (Printexc.to_string x) | ||
done |
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