summaryrefslogtreecommitdiff
path: root/src/main.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-10 10:11:16 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-10 10:11:16 +0100
commitd9fab442401005b49b9221b9d897501fef9a4d8d (patch)
treeff9fa0535f91d8d160c6e7360f256664d1b4169e /src/main.ml
parent8f1093f0e00f9b1df7ce343a879303fd56a95d08 (diff)
downloadLPC-Projet-d9fab442401005b49b9221b9d897501fef9a4d8d.tar.gz
LPC-Projet-d9fab442401005b49b9221b9d897501fef9a4d8d.zip
Nothing interesting to see yet.
Diffstat (limited to 'src/main.ml')
-rw-r--r--src/main.ml44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main.ml b/src/main.ml
new file mode 100644
index 0000000..8d78987
--- /dev/null
+++ b/src/main.ml
@@ -0,0 +1,44 @@
+open Format
+open Lexing
+
+let ifile = ref ""
+
+let set_var v s = v := s
+
+let usage = "usage: mini-cpp [options] file.cpp"
+
+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 options = []
+
+let () =
+ Arg.parse options (set_var ifile) usage;
+
+ if !ifile = "" then (
+ eprintf "No input file\n@?";
+ exit 1);
+
+ if not (Filename.check_suffix !ifile ".cpp") then (
+ eprintf "Input files must have suffix .cpp\n@?";
+ Arg.usage options usage;
+ exit 1);
+
+ let f = open_in !ifile in
+ let buf = Lexing.from_channel f in
+
+ try
+ while true do
+ print_string (Pretty.token_str (Lexer.token buf));
+ print_string "\n"
+ done
+ 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