summaryrefslogtreecommitdiff
path: root/src/main.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-16 10:57:43 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-16 10:57:43 +0100
commitdeb235f3045138908339cec56f0ce34dbb4e936b (patch)
tree8adc5dbee6113c25c2c0588a6d3c2fb20db58ad8 /src/main.ml
parent5dacc48b53568f673b03de794a9a13f7a5c11b0f (diff)
downloadLPC-Projet-deb235f3045138908339cec56f0ce34dbb4e936b.tar.gz
LPC-Projet-deb235f3045138908339cec56f0ce34dbb4e936b.zip
Started parser anew
Diffstat (limited to 'src/main.ml')
-rw-r--r--src/main.ml25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/main.ml b/src/main.ml
index 8d78987..719dcae 100644
--- a/src/main.ml
+++ b/src/main.ml
@@ -1,6 +1,8 @@
open Format
open Lexing
+let parse_only = ref false
+
let ifile = ref ""
let set_var v s = v := s
@@ -13,7 +15,14 @@ let localisation pos =
eprintf "File \"%s\", line %d, characters %d-%d:\n"
!ifile l (c-1) c
-let options = []
+let options = [
+ "-parse-only", Arg.Set parse_only, "Stops after parsing of the input file."
+ ]
+
+let localisation pos =
+ let l = pos.pos_lnum in
+ let c = pos.pos_cnum - pos.pos_bol + 1 in
+ eprintf "File \"%s\", line %d, characters %d-%d:\n" !ifile l (c-1) c
let () =
Arg.parse options (set_var ifile) usage;
@@ -31,14 +40,16 @@ let () =
let buf = Lexing.from_channel f in
try
- while true do
- print_string (Pretty.token_str (Lexer.token buf));
- print_string "\n"
- done
+ let p = Parser.prog Lexer.token buf in
+ close_in f;
+
+ Pretty.print_prog p;
with
- | Lexer.End_of_file ->
- exit 0
| Lexer.Lexing_error s ->
localisation (Lexing.lexeme_start_p buf);
eprintf "Lexical analysis error: %s@." s;
exit 1
+ | Parser.Error ->
+ localisation (Lexing.lexeme_start_p buf);
+ eprintf "Parsing error.@.";
+ exit 1