annotate lab2/main.ml @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
mike@0 1 (* lab2/main.ml *)
mike@0 2 (* Copyright (c) 2017 J. M. Spivey *)
mike@0 3
mike@0 4 open Print
mike@0 5 open Dict
mike@0 6 open Source
mike@0 7
mike@0 8 (* |main| -- main program *)
mike@0 9 let main () =
mike@0 10 let dflag = ref false in
mike@0 11 let fns = ref [] in
mike@0 12 let usage = "Usage: ppc [-d] file.p" in
mike@0 13 Arg.parse [("-d", Arg.Set dflag, " Print the tree");
mike@0 14 ("-O", Arg.Unit (fun () -> Kgen.optflag := true), " Peephole optimiser")]
mike@0 15 (function s -> fns := !fns @ [s]) usage;
mike@0 16 if List.length !fns <> 1 then begin
mike@0 17 fprintf stderr "$\n" [fStr usage]; exit 2
mike@0 18 end;
mike@0 19 let in_file = List.hd !fns in
mike@0 20 let in_chan = open_in in_file in
mike@0 21 Source.init in_file in_chan;
mike@0 22 let lexbuf = Lexing.from_channel in_chan in
mike@0 23 let prog = try Parser.program Lexer.token lexbuf with
mike@0 24 Parsing.Parse_error ->
mike@0 25 let tok = Lexing.lexeme lexbuf in
mike@0 26 err_message "syntax error at token '$'"
mike@0 27 [fStr tok] !Lexer.lineno;
mike@0 28 exit 1 in
mike@0 29
mike@0 30 if !dflag then Tree.print_tree stdout prog;
mike@0 31
mike@0 32 begin
mike@0 33 try Check.annotate prog with
mike@0 34 Check.Semantic_error (fmt, args, line) ->
mike@0 35 err_message fmt args line;
mike@0 36 exit 1
mike@0 37 end;
mike@0 38
mike@0 39 printf "MODULE Main 0 0\n" [];
mike@0 40 printf "IMPORT Lib 0\n" [];
mike@0 41 printf "ENDHDR\n\n" [];
mike@0 42 Kgen.translate prog;
mike@0 43 exit 0
mike@0 44
mike@0 45 let ppc = main ()