-
Notifications
You must be signed in to change notification settings - Fork 0
/
tigermain.sml
52 lines (48 loc) · 1.52 KB
/
tigermain.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
open tigerlex
open tigergrm
open BasicIO Nonstdio
open tigerpp
open tigerescap
open tigerseman
open tigertranslate
open tigercanon
open tigerassem
open tigerliv
open tigercoloring
fun lexstream(is: instream) =
Lexing.createLexer(fn b => fn n => buff_input is b 0 n);
fun errParsing(lbuf) = (print("Error en parsing!("
^(makestring(!num_linea))^
")["^(Lexing.getLexeme lbuf)^"]\n"); raise Fail "fin!")
fun main(args) =
let fun arg(l, s) = (List.exists (fn x => x=s) l, List.filter (fn x => x<>s) l)
val (arbol, l1) = arg(args, "-arbol")
val (escapes, l2) = arg(l1, "-escapes")
val (ir, l3) = arg(l2, "-ir")
val (canon, l4) = arg(l3, "-canon")
val (code, l5) = arg(l4, "-code")
val (flow, l6) = arg(l5, "-flow")
val (inter, l7) = arg(l6, "-inter")
val entrada =
case l7 of
[n] => ((open_in n)
handle _ => raise Fail (n^" no existe!"))
| [] => std_in
| _ => raise Fail "opcio'n dsconocida!"
val lexbuf = lexstream entrada
val expr = prog Tok lexbuf handle _ => errParsing lexbuf
in
if escapes then findEscape expr else ();
if arbol then (print"AST:\n"; exprAst expr) else ();
if ir then (transProg expr;()) else ();
if canon then canoFrags (!lfrags) else ();
if code then
let
val l = genera (!canonfrags)
fun f {frag=CPROC(ci,f),code=SOME e} = ((*printFun(f,e);*)printFun(f,coloreo (e,f)))
| f {frag=CSTRING(l,s),code} = printString(l,s)
| f _ = ()
in List.app f l end
else ()
end handle Fail s => print("Fail: "^s^"\n")
val _ = main(CommandLine.arguments())