Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/gen/opt/main.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/gen/opt/main.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2377 - (view) (download)

1 : jhr 1484 (* main.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure Main =
8 :     struct
9 :    
10 :     structure PP = TextIOPP
11 :    
12 :     (* prettyprinter for rule RHS *)
13 :     fun ppRHS (ppStrm, pat) = (case pat
14 :     of CheckSpec.WildPat => PP.string ppStrm "_"
15 :     | CheckSpec.IdPat x => PP.string ppStrm (CheckSpec.varToString x)
16 :     | CheckSpec.OpPat(rator, args) => (
17 :     PP.string ppStrm (CheckSpec.opToString rator);
18 :     PP.string ppStrm "(";
19 :     case args
20 :     of [] => ()
21 :     | [p] => ppRHS (ppStrm, p)
22 :     | (p::r) => (
23 :     ppRHS (ppStrm, p);
24 :     List.app
25 :     (fn p => (PP.string ppStrm ","; ppRHS (ppStrm, p))) r)
26 :     (* end case *);
27 :     PP.string ppStrm ")")
28 :     (* end case *))
29 :    
30 :     val ppDFA = DumpDFA.ppDFA ppRHS
31 :    
32 :     fun quitWithError srcFile = raise Fail("Error in compiling " ^ srcFile)
33 :    
34 :     (* check for errors and report them if there are any *)
35 :     fun checkForErrors errStrm = (
36 :     Error.report (TextIO.stdErr, errStrm);
37 :     if Error.anyErrors errStrm
38 :     then quitWithError (Error.sourceFile errStrm)
39 :     else ())
40 :    
41 :     fun doFile file = let
42 :     val inStrm = TextIO.openIn file
43 :     val errStrm = Error.mkErrStream file
44 :     val pt = RulesParser.parse (errStrm, inStrm)
45 :     val _ = TextIO.closeIn inStrm
46 :     in
47 :     case pt
48 :     of SOME spec => let
49 :     val CheckSpec.Spec rules = CheckSpec.check(errStrm, spec)
50 :     val dfa = CompileMatch.compile
51 :     (List.map (fn (CheckSpec.Rule r) => r) rules)
52 :     in
53 :     ppDFA (PP.openOut{dst=TextIO.stdOut, wid=120}, dfa)
54 :     end
55 :     | NONE => checkForErrors errStrm
56 :     (* end case *)
57 :     end
58 :    
59 :     end
60 :    
61 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0