1(* 2 Copyright (c) 2000 3 Cambridge University Technical Services Limited 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18*) 19 20 21(* 22 Title: Lexical symbols for ML compiler. 23 Author: Dave Matthews, Cambridge University Computer Laboratory 24 Copyright Cambridge University 1985 25*) 26 27structure Symbols : SymbolsSig = 28 29struct 30 datatype sys = 31 AbortParse 32 | Ident 33 | AbstypeSy 34 | AndSy 35 | AndalsoSy 36 | AsSy 37 | CaseSy 38 | DatatypeSy 39 | DoSy 40 | ElseSy 41 | EndSy 42 | ExceptionSy 43 | FnSy 44 | FunSy 45 | HandleSy 46 | IfSy 47 | InSy 48 | InfixSy 49 | InfixrSy 50 | LetSy 51 | LocalSy 52 | NonfixSy 53 | OfSy 54 | OpSy 55 | OpenSy 56 | OrelseSy 57 | RaiseSy 58 | RecSy 59 | ThenSy 60 | TypeSy 61 | ValSy 62 | WithSy 63 | WhileSy 64 | LeftParen 65 | RightParen 66 | LeftBrack 67 | RightBrack 68 | Comma 69 | Colon 70 | Semicolon 71 | ThickArrow 72 | VerticalBar 73 | EqualsSign 74 | Underline 75 | TypeIdent 76 | StringConst 77 | IntegerConst 78 | Asterisk 79 | Arrow 80 | RealConst 81 | LeftCurly 82 | RightCurly 83 | ThreeDots 84 | ColonGt 85 | HashSign 86 | StructureSy 87 | SignatureSy 88 | StructSy 89 | SigSy 90 | SharingSy 91 | FunctorSy 92 | WithtypeSy 93 | EqtypeSy 94 | IncludeSy 95 | WhereSy 96 | WordConst 97 | CharConst 98 | Othersy 99 100 fun repr AbortParse = "\^G" 101 | repr Ident = "<identifier>" 102 | repr AbstypeSy = "abstype" 103 | repr AndSy = "and" 104 | repr AndalsoSy = "andalso" 105 | repr AsSy = "as" 106 | repr CaseSy = "case" 107 | repr DatatypeSy = "datatype" 108 | repr DoSy = "do" 109 | repr ElseSy = "else" 110 | repr EndSy = "end" 111 | repr ExceptionSy = "exception" 112 | repr FnSy = "fn" 113 | repr FunSy = "fun" 114 | repr HandleSy = "handle" 115 | repr IfSy = "if" 116 | repr InSy = "in" 117 | repr InfixSy = "infix" 118 | repr InfixrSy = "infixr" 119 | repr LetSy = "let" 120 | repr LocalSy = "local" 121 | repr NonfixSy = "nonfix" 122 | repr OfSy = "of" 123 | repr OpSy = "op" 124 | repr OpenSy = "open" 125 | repr OrelseSy = "orelse" 126 | repr RaiseSy = "raise" 127 | repr RecSy = "rec" 128 | repr ThenSy = "then" 129 | repr TypeSy = "type" 130 | repr ValSy = "val" 131 | repr WithSy = "with" 132 | repr WhileSy = "while" 133 | repr LeftParen = "(" 134 | repr RightParen = ")" 135 | repr LeftBrack = "[" 136 | repr RightBrack = "]" 137 | repr Comma = "," 138 | repr Colon = ":" 139 | repr Semicolon = ";" 140 | repr ThickArrow = "=>" 141 | repr VerticalBar = "|" 142 | repr EqualsSign = "=" 143 | repr Underline = "_" 144 | repr TypeIdent = "<type identifier>" 145 | repr StringConst = "<string constant>" 146 | repr IntegerConst = "<integer constant>" 147 | repr Asterisk = "*" 148 | repr Arrow = "->" 149 | repr RealConst = "<real constant>" 150 | repr LeftCurly = "{" 151 | repr RightCurly = "}" 152 | repr ThreeDots = "..." 153 | repr ColonGt = ":>" 154 | repr HashSign = "#" 155 | repr StructureSy = "structure" 156 | repr SignatureSy = "signature" 157 | repr StructSy = "struct" 158 | repr SigSy = "sig" 159 | repr SharingSy = "sharing" 160 | repr FunctorSy = "functor" 161 | repr WithtypeSy = "withtype" 162 | repr EqtypeSy = "eqtype" 163 | repr IncludeSy = "include" 164 | repr WhereSy = "where" 165 | repr WordConst = "<word constant>" 166 | repr CharConst = "<char constant>" 167 | repr Othersy = "unknown symbol" 168 169 local 170 open HashTable; 171 172 val reservedWords = 173 [ 174 AbstypeSy, 175 AndSy, 176 AndalsoSy, 177 AsSy, 178 CaseSy, 179 DatatypeSy, 180 DoSy, 181 ElseSy, 182 EndSy, 183 ExceptionSy, 184 FnSy, 185 FunSy, 186 HandleSy, 187 IfSy, 188 InSy, 189 InfixSy, 190 InfixrSy, 191 LetSy, 192 LocalSy, 193 NonfixSy, 194 OfSy, 195 OpSy, 196 OpenSy, 197 OrelseSy, 198 RaiseSy, 199 RecSy, 200 ThenSy, 201 TypeSy, 202 ValSy, 203 WithSy, 204 WhileSy, 205 StructureSy, 206 SignatureSy, 207 StructSy, 208 SigSy, 209 SharingSy, 210 FunctorSy, 211 WithtypeSy, 212 EqtypeSy, 213 IncludeSy, 214 WhereSy, 215 (* Reserved or special symbols *) 216 Arrow, 217 EqualsSign, 218 ThickArrow, 219 Asterisk, 220 ColonGt, 221 Underline, 222 Colon, 223 VerticalBar, 224 HashSign 225 ] 226 227 local 228 (* Make table sparse to minimise collisions. *) 229 val table = hashMake (4 * List.length reservedWords); 230 231 (* Enter each reserved word in the hash table *) 232 val () = List.app (fn n => hashSet (table, repr n, n)) reservedWords 233 in 234 val table = hashFreeze table 235 end 236 in 237 (* Returns the symbol if it is in the table else ident *) 238 fun lookup str = getOpt(hashSub (table, str), Ident); 239 end; 240 241end (* Symbols *); 242