docs(Makefile, interf, use): Makefile, interf, use

This commit is contained in:
Laurian-Dufrechou
2023-04-06 23:53:48 +02:00
parent 8f35bdb9f7
commit 78fd8371cb
3 changed files with 95 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
all: lang.cmo parser.cmo lexer.cmo interf.cmo
# Compilation of .ml files
lang.cmo: lang.ml
ocamlc -c $<
# typing.cmo: typing.ml lang.cmo
# ocamlc -c $<
# instrs.cmo: instrs.ml lang.cmo
# ocamlc -c $<
# gen.cmo: gen.ml lang.cmo instrs.cmo typing.cmo
# ocamlc -c $<
#interf.cmo: interf.ml lexer.cmo parser.cmo gen.cmo typing.cmo
interf.cmo: interf.ml lexer.cmo parser.cmo
ocamlc -c $<
# comp.cmo: comp.ml gen.cmo typing.cmo parser.cmo interf.cmo
# ocamlc -c $<
# ocaml lexer and parser
lexer.ml: lexer.mll lang.cmo
ocamllex $<
parser.ml parser.mli: parser.mly lang.cmo
ocamlyacc $<
lexer.cmo: lexer.ml parser.cmo
ocamlc -c $<
parser.cmo: parser.ml parser.cmi lang.cmo
ocamlc -c $<
#### Generic rules
%.cmi: %.mli
ocamlc -c $<
.PHONY: clean
clean:
rm -f lexer.ml parser.ml *.mli *.cmi *.cmo
+33
View File
@@ -0,0 +1,33 @@
(* Interface with parser *)
exception ParseLexError of exn * (string * int * int * string * string)
let parse_file infile =
let lexbuf = Lexing.from_channel (open_in infile) in
try
Parser.start Lexer.token lexbuf
with exn ->
begin
let curr = lexbuf.Lexing.lex_curr_p in
let line = curr.Lexing.pos_lnum in
let cnum = curr.Lexing.pos_cnum - curr.Lexing.pos_bol in
let tok = Lexing.lexeme lexbuf in
let tail = Lexer.ruleTail "" lexbuf in
raise (ParseLexError (exn,(infile, line,cnum,tok,tail)))
end
;;
let print_parse_error (filename, line,cnum,tok,tail) =
print_string ("Parsing error in file: " ^ filename ^
" on line: " ^ (string_of_int line) ^
" column: " ^ (string_of_int cnum) ^
" token: " ^ tok ^
"\nrest: " ^ tail ^ "\n")
;;
let parse infile =
try parse_file infile
with ParseLexError (e, r) ->
print_parse_error r;
failwith "Stopped execution."
;;
+16
View File
@@ -0,0 +1,16 @@
#load "lang.cmo";;
#load "parser.cmo" ;;
#load "lexer.cmo" ;;
#load "interf.cmo";;
open Interf;;
open Lang;;
(* For using the parser:
- Evaluate this file (use.ml)
- parse "Tests/progsimple.c" ;;
*)