Skip to content

Commit

Permalink
Reorganizing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Berke Durak committed Jan 22, 2009
1 parent 538ad02 commit e0c83c5
Show file tree
Hide file tree
Showing 30 changed files with 247 additions and 662 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DISTRIB=_build/aurochs-$(VERSION)
all: targets

targets:
@./build.sh aurochs_lib.cma aurochs_lib.cmxa aurochs_tool.native aurochs/test_aurochs.native cnog/check
@./build.sh aurochs_lib.cma aurochs_lib.cmxa aurochs_tool.native aurochs/test_aurochs.native c/test/test_nog

clean:
rm -rf _build/
Expand Down
2 changes: 1 addition & 1 deletion _tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#<*/*.c>: cstuff
<*/*.c>: cstuff, optimize
<**/*.c>: cstuff, optimize
<genmachine.{byte,native}>: use_str, use_unix
<{aurochs/aurochs_tool,aurochs/test_aurochs,tests/test_{arith,inline}}.{byte,native}>: use_libaurochs
<{util,peg,pack,syntax,nog,backends,front,aurochs}/*.cmx>: for-pack(Aurochs_pack)
Expand Down
16 changes: 6 additions & 10 deletions aurochs/aurochs_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
#include <caml/alloc.h>
#include <caml/custom.h>

#include <base_types.h>
#include <alloc.h>
#include <staloc.h>

#if 0
#define DEBUGF(x, y...) printf("DEBUG " __FILE__ ":" x "\n", ##y);
#else
#define DEBUGF(x,...)
#endif

#include <alloc.h>

typedef value tree;
typedef value attribute;
typedef struct {
Expand All @@ -31,9 +29,7 @@ typedef construction_t *construction;

#define BUILDER_TYPES_DEFINED 1

#include <peg.h>
#include <cnog.h>
#include <peg_lib.h>
#include <aurochs.h>

typedef struct {
nog_program_t *p_nog;
Expand Down Expand Up @@ -111,7 +107,7 @@ value caml_aurochs_program_of_binary(value binaryv)
if(pack_init_from_string(&pk, binary, length)) {
s = staloc_create(&alloc_stdlib);
if(s) {
pg = cnog_unpack_program(&s->s_alloc, &pk);
pg = nog_unpack_program(&s->s_alloc, &pk);
if(pg) {
programv = program_alloc(pg, s);
CAMLreturn(programv);
Expand Down Expand Up @@ -414,15 +410,15 @@ value caml_aurochs_parse(value programv, value uv, value errorv)
caml_failwith("Can't allocate context");
}

if(cnog_execute(cx, pg, &treev)) {
if(nog_execute(cx, pg, &treev)) {
peg_delete_context(cx);
staloc_dispose(s);
CAMLreturn(some(treev));
} else {
/* We've got a parse error, compute its position. */
int pos;

pos = cnog_error_position(cx, pg);
pos = nog_error_position(cx, pg);
Store_field(errorv, 0, Val_int(pos));
peg_delete_context(cx);
staloc_dispose(s);
Expand Down
12 changes: 10 additions & 2 deletions aurochs/aurochs_tool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module Spec =
| "c" -> targets += `c
| _ -> raise (Bad "Invalid target")
end),
" target language";
" Type of parser to generate. (nog: Aurochs parsing automaton as a binary file; c_table_nog: nog as a C table;
ml: nog as ML string; c: direct parsing using C code";

"-load-nog",
String(aor load_nog),
Expand Down Expand Up @@ -209,7 +210,14 @@ let _ =
Arg.parse
Spec.specs
(fun x -> did_something := true; Process.process (Some x))
(sf "Usage: %s [options] <grammar-file>" progname);
(sf
"Usage:\n\
\ 1. %s -parse file grammar.peg\n\
\ 2. %s -target nog grammar.peg\n\
\ 3. %s -load-nog grammar.nog -parse file\n\
\n\
Options:\n"
progname progname progname);

(* Consistency checks *)
if (!Opt.debug || !Opt.trace) && !Opt.interpreter != `mlnog then
Expand Down
10 changes: 3 additions & 7 deletions aurochs/bootstrap.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
(* Bootstrap *)

open Pffpsf;;
open Peg;;
open Pffpsf
open Peg

(*** load_grammar *)
let load_grammar fn =
let u = Driver.read_file fn in
let u = Util.read_file fn in
let m = String.length u in
let peg = Grammar_original.peg in
(*with_file_output "internal.peg" (fun oc -> Pretty.print_grammar oc peg);*)
Expand All @@ -20,13 +19,10 @@ let load_grammar fn =
raise (Error(sf "Error in grammar file %S at character %d" fn (i + 1)))
with
| Peg.Fail -> raise (Error(sf "Cannot parse grammar file %S" fn))
;;
(* ***)

let _ =
let fn = "syntax/grammar.peg" in
let peg = load_grammar fn in
let peg = Canonify.canonify_grammar ~start:!Opt.start peg in
let nog = Noggie.generate "grammar" ~root:"Root" ~start:"start" peg in
Camelus.generate_implementation ~pack:false "syntax/grammar" "start" peg nog
;;
40 changes: 1 addition & 39 deletions aurochs/driver.ml
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
(* Driver *)

open Peg;;
open Peg

open Pffpsf;;

(*let process (start : peg) u =
try
let (q, i, t) = Peg.descent (fun x -> x) start u in
fp stdout "%b %d\n%a\n%!" q i (Peg.print_tree ~depth:0) t
with
| Peg.Fail ->
fp stdout "Does not parse.\n%!"
;;
let line_driver start =
try
while true do
(*fp stdout "Query? %!";*)
let l = input_line stdin in
fp stdout "%s\n" l;
process start l
done
with
| End_of_file ->
()
(*fp stdout "\nBye.\n%!"*)
;;*)

let read_file fn =
let ic = open_in fn in
let m = in_channel_length ic in
let u = String.create m in
really_input ic u 0 m;
close_in ic;
u
;;

(*let file_driver start fn =
let u = read_file fn in
process start u
;;*)
33 changes: 12 additions & 21 deletions aurochs/process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type 'a name =
| Unresolved of string

let bootstrap fn =
let u = Driver.read_file fn in
let u = Util.read_file fn in
let m = String.length u in
let peg = Grammar_original.peg in
with_file_output "internal.peg" (fun oc -> Pretty.print_grammar oc peg);
Expand All @@ -41,7 +41,6 @@ let bootstrap fn =

module SM = Map.Make(String)

(*** build_color_table *)
let build_color_table ?(min_color=1) ?(max_color=7) t =
let color = ref min_color in
let builds_table = ref SM.empty in
Expand All @@ -58,8 +57,6 @@ let build_color_table ?(min_color=1) ?(max_color=7) t =
Peg.iter_over_poly_tree_attributes (fun a -> add_color attributes_table a) t;
(!builds_table, !attributes_table)

(* ***)
(*** colorize *)
let colorize ?(default_acolor=Ansi.black) ?(default_bcolor=Ansi.white) (builds_table, attributes_table) u pt =
let m = String.length u in
let ac = Array.make (m + 1) default_acolor in
Expand Down Expand Up @@ -88,8 +85,6 @@ let colorize ?(default_acolor=Ansi.black) ?(default_bcolor=Ansi.white) (builds_t
loop_build pt;
(ac, bc)

(* ***)
(*** dump_colorized *)
let dump_colorized oc (ac, bc) u =
let m = String.length u in
let last_fg_color = ref (-1) in
Expand Down Expand Up @@ -122,9 +117,7 @@ let dump_colorized oc (ac, bc) u =
done;
fp oc "%s%!" Ansi.none

(* ***)

(*** parse_file_with_nog *)
let parse_file_with_nog pg fn =
let with_dump_oc =
match !Opt.dump_colorized with
Expand Down Expand Up @@ -208,10 +201,8 @@ let parse_file_with_nog pg fn =
| End_of_file -> ()
end
else
treat (Driver.read_file fn)
treat (Util.read_file fn)

(* ***)
(*** parse_file_with_prog *)
let parse_file_with_prog prog fn =
let with_dump_oc =
match !Opt.dump_colorized with
Expand Down Expand Up @@ -267,10 +258,8 @@ let parse_file_with_prog prog fn =
| End_of_file -> ()
end
else
treat (Driver.read_file fn)
treat (Util.read_file fn)

(* ***)
(*** parse_file *)
let parse_file peg fn =
(*let peg' =
List.map
Expand Down Expand Up @@ -331,10 +320,8 @@ let parse_file peg fn =
end
end
else
treat (Driver.read_file fn)
treat (Util.read_file fn)

(* ***)
(*** process *)
let process fno =
let (v1,v2,v3) = Version.version in
banner "Aurochs %d.%d.%d" v1 v2 v3;
Expand All @@ -346,9 +333,14 @@ let process fno =
| Some fn ->
let u = Aurochs.read_file fn in
info `Normal "Grammar loaded from file %s" fn;
let peg = Convert_grammar.convert_grammar (Grammar.parse u) in
info `Minor "Grammar converted";
peg
try
let peg = Convert_grammar.convert_grammar (Grammar.parse u) in
info `Minor "Grammar converted";
peg
with
| Nog.Parse_error i ->
info `Important "PARSE ERROR IN GRAMMAR FILE %s AT CHARACTER %d" fn i;
exit 1
end
in

Expand Down Expand Up @@ -488,4 +480,3 @@ let process fno =
)
targets

(* ***)
2 changes: 1 addition & 1 deletion aurochs/version.ml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let version = (1,0,93)
let version = (1,0,94)
Loading

0 comments on commit e0c83c5

Please sign in to comment.