diff options
author | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-04-30 17:19:08 +0200 |
---|---|---|
committer | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-04-30 17:19:08 +0200 |
commit | bcde99fbe99174a094f38fdda70ad69d65a423f4 (patch) | |
tree | 21e16494aba19c4a63d55eba877abfe7fe5d8e80 /frontend/file_parser.ml | |
download | SemVerif-Projet-bcde99fbe99174a094f38fdda70ad69d65a423f4.tar.gz SemVerif-Projet-bcde99fbe99174a094f38fdda70ad69d65a423f4.zip |
Fist commit (WIP)
Diffstat (limited to 'frontend/file_parser.ml')
-rw-r--r-- | frontend/file_parser.ml | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/frontend/file_parser.ml b/frontend/file_parser.ml new file mode 100644 index 0000000..fa7ff7d --- /dev/null +++ b/frontend/file_parser.ml @@ -0,0 +1,32 @@ +(* + Cours "Sémantique et Application à la Vérification de programmes" + + Antoine Miné 2014 + Ecole normale supérieure, Paris, France / CNRS / INRIA +*) + +(* + Opens and parses a file given as argument. +*) + +open Abstract_syntax_tree +open Abstract_syntax_printer +open Lexing + +(* parsing, with nice error messages *) + +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" |