1(*
2    Copyright (c) 2000
3        Cambridge University Technical Services Limited
4        
5    Cleaned up: David C.J. Matthews 2010
6
7    This library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public
9    License as published by the Free Software Foundation; either
10    version 2.1 of the License, or (at your option) any later version.
11    
12    This library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
16    
17    You should have received a copy of the GNU Lesser General Public
18    License along with this library; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20*)
21
22(*
23    Title:      Symbols Sets.
24    Author:     Dave Matthews, Cambridge University Computer Laboratory
25    Copyright   Cambridge University 1985
26*)
27
28(*
29These symbol sets are used in the parsing process.  The only way they
30are actually used is the "inside" function which tests if a symbol
31is in the set.  The representation used minimises the memory needed
32to implement each set union (++ operator).
33*)
34
35structure SymSet :> SymsetSig where type sys = Symbols.sys =
36
37(*****************************************************************************)
38(*                  SYMSET functor body                                      *)
39(*****************************************************************************)
40struct
41    open Symbols
42  
43    datatype symset = Set of sys -> bool
44
45    val empty = Set (fn _ => false);
46    infix 6 ++;
47(* ...  
48    fun plus  (Set f, Set g) = Set (fn x => f x orelse g x);
49... *)
50    (* Experiment! *) 
51    fun (Set f) ++ (Set g) = Set (fn x => g x orelse f x);
52  
53    infix 5 inside
54
55    fun sym inside (Set s) = s sym
56
57    val abortParse     = Set(fn AbortParse => true | _ => false)
58    val ident          = Set(fn Ident => true | _ => false)
59    val abstypeSy      = Set(fn AbstypeSy => true | _ => false)
60    val andSy          = Set(fn AndSy => true | _ => false)
61    val andalsoSy      = Set(fn AndalsoSy => true | _ => false)
62    val asSy           = Set(fn AsSy => true | _ => false)
63    val caseSy         = Set(fn CaseSy => true | _ => false)
64    val datatypeSy     = Set(fn DatatypeSy => true | _ => false)
65    val doSy           = Set(fn DoSy => true | _ => false)
66    val elseSy         = Set(fn ElseSy => true | _ => false)
67    val endSy          = Set(fn EndSy => true | _ => false)
68    val exceptionSy    = Set(fn ExceptionSy => true | _ => false)
69    val fnSy           = Set(fn FnSy => true | _ => false)
70    val funSy          = Set(fn FunSy => true | _ => false)
71    val handleSy       = Set(fn HandleSy => true | _ => false)
72    val ifSy           = Set(fn IfSy => true | _ => false)
73    val inSy           = Set(fn InSy => true | _ => false)
74    val infixSy        = Set(fn InfixSy => true | _ => false)
75    val infixrSy       = Set(fn InfixrSy => true | _ => false)
76    val letSy          = Set(fn LetSy => true | _ => false)
77    val localSy        = Set(fn LocalSy => true | _ => false)
78    val nonfixSy       = Set(fn NonfixSy => true | _ => false)
79    val ofSy           = Set(fn OfSy => true | _ => false)
80    val opSy           = Set(fn OpSy => true | _ => false)
81    val openSy         = Set(fn OpenSy => true | _ => false)
82    val orelseSy       = Set(fn OrelseSy => true | _ => false)
83    val raiseSy        = Set(fn RaiseSy => true | _ => false)
84    val recSy          = Set(fn RecSy => true | _ => false)
85    val thenSy         = Set(fn ThenSy => true | _ => false)
86    val typeSy         = Set(fn TypeSy => true | _ => false)
87    val valSy          = Set(fn ValSy => true | _ => false)
88    val withSy         = Set(fn WithSy => true | _ => false)
89    val whileSy        = Set(fn WhileSy => true | _ => false)
90    val structureSy    = Set(fn StructureSy => true | _ => false)
91    val signatureSy    = Set(fn SignatureSy => true | _ => false)
92    val structSy       = Set(fn StructSy => true | _ => false)
93    val sigSy          = Set(fn SigSy => true | _ => false)
94    val sharingSy      = Set(fn SharingSy => true | _ => false)
95    val functorSy      = Set(fn FunctorSy => true | _ => false)
96    val withtypeSy     = Set(fn WithtypeSy => true | _ => false)
97    val eqtypeSy       = Set(fn EqtypeSy => true | _ => false)
98    val includeSy      = Set(fn IncludeSy => true | _ => false)
99    val whereSy        = Set(fn WhereSy => true | _ => false)
100    val leftParen      = Set(fn LeftParen => true | _ => false)
101    val rightParen     = Set(fn RightParen => true | _ => false)
102    val leftBrack      = Set(fn LeftBrack => true | _ => false)
103    val rightBrack     = Set(fn RightBrack => true | _ => false)
104    val comma          = Set(fn Comma => true | _ => false)
105    val colon          = Set(fn Colon => true | _ => false)
106    val semicolon      = Set(fn Semicolon => true | _ => false)
107    val verticalBar    = Set(fn VerticalBar => true | _ => false)
108    val equalsSign     = Set(fn EqualsSign => true | _ => false)
109    val thickArrow     = Set(fn ThickArrow => true | _ => false)
110    val underline      = Set(fn Underline => true | _ => false)
111    val typeIdent      = Set(fn TypeIdent => true | _ => false)
112    val stringConst    = Set(fn StringConst => true | _ => false)
113    val integerConst   = Set(fn IntegerConst => true | _ => false)
114    val realConst      = Set(fn RealConst => true | _ => false)
115    val wordConst      = Set(fn WordConst => true | _ => false)
116    val charConst      = Set(fn CharConst => true | _ => false)
117    val asterisk       = Set(fn Asterisk => true | _ => false)
118    val arrow          = Set(fn Arrow => true | _ => false)
119    val leftCurly      = Set(fn LeftCurly => true | _ => false)
120    val rightCurly     = Set(fn RightCurly => true | _ => false)
121    val threeDots      = Set(fn ThreeDots => true | _ => false)
122    val colonGt        = Set(fn ColonGt => true | _ => false)
123    val hashSign       = Set(fn HashSign => true | _ => false)
124    val othersy        = Set(fn Othersy => true | _ => false)
125  
126  (* Collections of symbol sets for various syntactic elements *)
127
128  (* Symbols which can be declared as identifiers *)
129  val declarableVarSys = ident ++ asterisk;
130
131  (* Symbols which can be variables *)
132  val variableSys = declarableVarSys ++ equalsSign;
133
134  (* Symbols which can be constructors *)
135  val constructorSys =
136    declarableVarSys ++ stringConst ++ integerConst ++
137    realConst ++ wordConst ++ charConst;
138
139  (* The symbols which can start an atomic expression *)
140  val startAtomicSys = 
141    letSy ++ opSy ++ leftBrack ++ leftParen ++ leftCurly ++ 
142    variableSys ++ constructorSys ++ hashSign;
143
144  (* The symbols which can start a pattern, Note: "=" is not among them. *)
145  (* real constants are not allowed in patterns in ML97.  We leave them
146     in and sort it out later. *)
147  val startPatternSys =
148    underline ++ declarableVarSys ++ constructorSys ++ 
149    leftParen ++ leftBrack ++ leftCurly ++ opSy;
150
151  (* The symbols which can start a match *)
152  val startMatchSys = startPatternSys;
153
154  (* The symbols which can start an expression *)
155  val startExpressionSys = 
156    raiseSy ++ ifSy ++ whileSy ++ caseSy ++ fnSy ++ startAtomicSys;
157
158  (* The symbols which can start a declaration *)
159  val startDecSys =
160    valSy ++ typeSy ++ abstypeSy ++ exceptionSy ++ localSy ++ 
161    infixSy ++ infixrSy ++ nonfixSy ++ openSy ++ funSy ++ datatypeSy;
162
163  (* Symbols which can start a type. *)
164  val startTypeSys = typeIdent ++ ident ++ leftParen ++ leftCurly;
165
166  (* Symbols which can start a signature.  Strictly speaking
167     "sharing" cannot start a signature. *)
168  val startSigSys =
169    datatypeSy ++ typeSy ++ eqtypeSy ++ valSy ++ exceptionSy ++ 
170    structureSy ++ sharingSy ++ includeSy;
171 
172  val startTopSys =
173    structureSy ++ functorSy ++ signatureSy ++ startDecSys ++ startExpressionSys
174end;
175
176