Commit e11f4747 authored by POTTIER Francois's avatar POTTIER Francois

Merged [PreFront] into [Front].

parent 07d78169
(* Start where [PreFront] left off. *)
(* The front-end. This module performs a series of toplevel side effects. *)
let grammar =
PreFront.grammar
(* ------------------------------------------------------------------------- *)
(* Reading a grammar from a file. *)
let load_partial_grammar filename =
let validExt = if Settings.coq then ".vy" else ".mly" in
if not (Filename.check_suffix filename validExt) then
Error.error [] (Printf.sprintf
"argument file names should end in %s. \"%s\" is not accepted."
validExt filename);
Error.set_filename filename;
try
let contents = IO.read_whole_file filename in
Error.file_contents := Some contents;
let lexbuf = Lexing.from_string contents in
lexbuf.Lexing.lex_curr_p <-
{
Lexing.pos_fname = filename;
Lexing.pos_lnum = 1;
Lexing.pos_bol = 0;
Lexing.pos_cnum = 0
};
let grammar =
{ (Parser.grammar Lexer.main lexbuf) with ConcreteSyntax.pg_filename = filename }
in
Error.file_contents := None;
grammar
with Sys_error msg ->
Error.error [] msg
(* ------------------------------------------------------------------------- *)
(* Read all of the grammar files that are named on the command line. *)
let partial_grammars =
List.map load_partial_grammar Settings.filenames
let () =
Time.tick "Lexing and parsing"
(* ------------------------------------------------------------------------- *)
(* If several grammar files were specified, merge them. *)
let parameterized_grammar =
PartialGrammar.join_partial_grammars partial_grammars
(* ------------------------------------------------------------------------- *)
(* Expand away all applications of parameterized nonterminal symbols, so as to
obtain a grammar without parameterized nonterminal symbols. *)
let grammar =
ParameterizedGrammar.expand parameterized_grammar
let () =
Time.tick "Joining and expanding"
(* ------------------------------------------------------------------------- *)
(* If [--only-tokens] was specified on the command line, produce
the definition of the [token] type and stop. *)
......@@ -9,6 +68,8 @@ let grammar =
let () =
TokenType.produce_tokentype grammar
(* ------------------------------------------------------------------------- *)
(* Perform reachability analysis. *)
let grammar =
......@@ -17,8 +78,10 @@ let grammar =
let () =
Time.tick "Trimming"
(* If [--depend] was specified on the command line, perform
dependency analysis and stop. *)
(* ------------------------------------------------------------------------- *)
(* If [--depend] was specified on the command line, perform dependency
analysis and stop. *)
let () =
match Settings.depend with
......@@ -28,6 +91,8 @@ let () =
| Settings.OMNone ->
()
(* ------------------------------------------------------------------------- *)
(* If [--infer] was specified on the command line, perform type inference.
The OCaml type of every nonterminal is then known. *)
......@@ -39,6 +104,8 @@ let grammar =
else
grammar
(* ------------------------------------------------------------------------- *)
(* If [--no-inline] was specified on the command line, skip the
inlining of non terminal definitions marked with %inline. *)
......@@ -57,6 +124,8 @@ let grammar =
else
grammar
(* ------------------------------------------------------------------------- *)
(* If [--only-preprocess] or [--only-preprocess-drop] was specified on the
command line, print the grammar and stop. Otherwise, continue. *)
......
(* This module drives the second half of the front-end. It starts
where [PreFront] left off, and performs type inference. This yields
the grammar that the back-end works with (through the interface
provided by module [Grammar]). *)
(* This module drives the front-end. It opens and parses the input files,
which yields a number of partial grammars. It joins these grammars, expands
them to get rid of parameterized nonterminals, and performs reachability
analysis. This yields a single unified grammar. It then performs type
inference. This yields the grammar that the back-end works with (often
through the interface provided by module [Grammar]). *)
val grammar: UnparameterizedSyntax.grammar
(* The front-end. *)
(* ------------------------------------------------------------------------- *)
(* Reading a grammar from a file. *)
let load_partial_grammar filename =
let validExt = if Settings.coq then ".vy" else ".mly" in
if not (Filename.check_suffix filename validExt) then
Error.error [] (Printf.sprintf
"argument file names should end in %s. \"%s\" is not accepted."
validExt filename);
Error.set_filename filename
try
let contents = IO.read_whole_file filename in
Error.file_contents := Some contents;
let lexbuf = Lexing.from_string contents in
lexbuf.Lexing.lex_curr_p <-
{
Lexing.pos_fname = filename;
Lexing.pos_lnum = 1;
Lexing.pos_bol = 0;
Lexing.pos_cnum = 0
};
let grammar =
{ (Parser.grammar Lexer.main lexbuf) with ConcreteSyntax.pg_filename = filename }
in
Error.file_contents := None;
grammar
with Sys_error msg ->
Error.error [] msg
(* ------------------------------------------------------------------------- *)
(* Read all of the grammar files that are named on the command line. *)
let partial_grammars =
List.map load_partial_grammar Settings.filenames
let () =
Time.tick "Lexing and parsing"
(* ------------------------------------------------------------------------- *)
(* If several grammar files were specified, merge them. *)
let parameterized_grammar =
PartialGrammar.join_partial_grammars partial_grammars
(* ------------------------------------------------------------------------- *)
(* Expand away all applications of parameterized nonterminal symbols, so as to
obtain a grammar without parameterized nonterminal symbols. *)
let grammar =
ParameterizedGrammar.expand parameterized_grammar
let () =
Time.tick "Joining and expanding"
(* This module drives the first half of the front-end. It opens and
parses the input files, which yields a number of partial
grammars. It joins these grammars, expands them to get rid of
parameterized nonterminals, and performs reachability
analysis. This yields a single unified grammar.
More transformations over this grammar are performed in the second
half of the front-end, which is driven by [Front]. The modules
[PreFront] and [Front] are separated because it is convenient to
insert auxiliary modules, such as [TokenType] and [Infer], in
between the two. *)
val grammar: UnparameterizedSyntax.grammar
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment