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/keywords.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2377 - (view) (download)

1 : jhr 1484 (* keywords.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure Keywords : sig
8 :    
9 :     val idToken : string -> RulesTokens.token
10 :    
11 :     end = struct
12 :    
13 :     structure T = RulesTokens
14 :    
15 :     (* these are a subset of the operators; eventually, these will be either generated
16 :     * by the IL generator tool or become part of the specification.
17 :     *)
18 :     val keywords = [
19 :     "Dot",
20 :     "Add",
21 :     "Sub",
22 :     "Mul",
23 :     "Div",
24 :     "Neg",
25 :     "Scale",
26 :     "Kernel",
27 :     "LoadImage",
28 :     "Field",
29 :     "SubField",
30 :     "ScaleField",
31 :     "NegField",
32 :     "ProbeField",
33 :     "Inside",
34 :     "DiffField",
35 :     "AddField",
36 :     "DotField"
37 :     ]
38 :    
39 : jhr 1485 (* create a keyword lookup table *)
40 : jhr 1484 fun mkFind kws = let
41 : jhr 1485 (* creates empty hashtable *)
42 : jhr 1484 val tbl = AtomTable.mkTable (17, Fail "keywords")
43 : jhr 1485 fun ins id =let
44 :     val id=Atom.atom id
45 :     in
46 :     AtomTable.insert tbl (id, T.OPER id)
47 :     end
48 : jhr 1484 val find = AtomTable.find tbl
49 :     fun idToken id = let
50 :     val id = Atom.atom id
51 :     in
52 :     case find id
53 : jhr 1485 of NONE => T.ID id (* does not find the kw *)
54 :     | SOME kw => kw (* finds the keywords*)
55 :     (* end case *)
56 : jhr 1484 end
57 :     in
58 : jhr 1485 List.app ins kws; (* seed hash table with keywords *)
59 : jhr 1484 idToken
60 :     end
61 :    
62 :     val idToken = mkFind keywords
63 :    
64 :     end

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