summaryrefslogtreecommitdiff
path: root/frontend/file_parser.ml
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ansys.com>2014-06-11 16:41:43 +0200
committerAlex Auvolat <alex.auvolat@ansys.com>2014-06-11 16:41:43 +0200
commit36f98d819756ada119e696729e40d8e8e427b5f0 (patch)
treecacac900a6923e68911756c335f0dfaa61fcfba5 /frontend/file_parser.ml
downloadscade-analyzer-36f98d819756ada119e696729e40d8e8e427b5f0.tar.gz
scade-analyzer-36f98d819756ada119e696729e40d8e8e427b5f0.zip
Initial commit: parser for tiny subset of SCADE language...
Diffstat (limited to 'frontend/file_parser.ml')
-rw-r--r--frontend/file_parser.ml19
1 files changed, 19 insertions, 0 deletions
diff --git a/frontend/file_parser.ml b/frontend/file_parser.ml
new file mode 100644
index 0000000..0e975ce
--- /dev/null
+++ b/frontend/file_parser.ml
@@ -0,0 +1,19 @@
+open Ast
+open Ast_printer
+open Lexing
+
+let parse_file (filename : string) : prog =
+ let f = open_in filename in
+ let lex = from_channel f in
+ try
+ lex.lex_curr_p <- { lex.lex_curr_p with pos_fname = filename; };
+ Parser.file Lexer.token lex
+ with
+ | Parser.Error ->
+ Printf.eprintf "Parse error (invalid syntax) near %s\n"
+ (string_of_position lex.lex_start_p);
+ failwith "Parse error"
+ | Failure "lexing: empty token" ->
+ Printf.eprintf "Parse error (invalid token) near %s\n"
+ (string_of_position lex.lex_start_p);
+ failwith "Parse error"