2 * $XConsortium: ParseTree.hh /main/3 1996/06/11 16:21:45 cde-hal $
4 * Copyright (c) 1991 HaL Computer Systems, Inc. All rights reserved.
5 * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
9 * This software contains confidential information and trade secrets of HaL
10 * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
11 * without the prior express written permission of HaL Computer Systems, Inc.
13 * RESTRICTED RIGHTS LEGEND
14 * Use, duplication, or disclosure by the Government is subject to
15 * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
16 * Technical Data and Computer Software clause at DFARS 252.227-7013.
17 * HaL Computer Systems, Inc.
18 * 1315 Dell Avenue, Campbell, CA 95008
25 typedef void *ClassType;
49 typedef enum { USER_REQUEST, OBJECT_REQUEST } delete_request_t;
51 /* -------- PNode -------- */
55 static const ClassType PNodeClass;
56 void *f_user_data; // allow app to attach misc data to nodes
57 /* we're dead in multi-threaded environment with statics like this */
58 static bool f_recursive_delete;
60 PNode *f_parent; // parent in parse tree
61 PNode *f_previous; // next symbol in linear ordering
62 PNode *f_next; // previous symbol in linear ordering
67 virtual bool isa (ClassType type)
68 { return (type == PNodeClass ? TRUE : FALSE); }
69 virtual const ClassType type () = 0;
70 virtual char *symbol ()
71 { return " *ERROR* "; }
72 virtual const int precedence ()
73 { abort (); return (0); }
74 virtual void replace_child (PNode *, PNode *)
75 { puts ("ERROR: BOGUS replace_child CALLED!!"); abort (); }
76 static void insert (PRoot *root, long position);
77 static bool can_insert (PRoot *root, long position);
78 virtual void delete_self (delete_request_t)
79 { puts ("*** Tried to delete something without delete method ***"); }
81 protected: // functions
82 PNode (PNode *parent, PNode *previous, PNode *next);
85 /* -------- PStart -------- */
87 class PStart : public PNode {
89 static const ClassType PStartClass;
92 PStart (PNode *parent, PNode *previous, PNode *next)
93 : PNode (parent, previous, next) { };
95 virtual bool isa (ClassType type)
96 { return (type == PStartClass ? TRUE : PNode::isa (type)); }
97 virtual const ClassType type ()
98 { return PStartClass; }
99 virtual char *symbol ()
102 protected: // variables
103 static char *f_symbol;
104 static const int f_precedence;
107 /* -------- PEnd -------- */
109 class PEnd : public PNode {
111 static const ClassType PEndClass;
114 PEnd (PNode *parent, PNode *previous, PNode *next)
115 : PNode (parent, previous, next) { };
117 virtual bool isa (ClassType type)
118 { return (type == PEndClass ? TRUE : PNode::isa (type)); }
119 virtual const ClassType type ()
120 { return PEndClass; }
121 virtual char *symbol ()
124 protected: // variables
125 static char *f_symbol;
126 static const int f_precedence;
129 /* -------- PText -------- */
131 class PText : public PNode {
133 static const ClassType PTextClass;
137 PText (PNode *parent, PNode *previous, PNode *next, char *str);
139 void insert_chars (int where, char *text, int length);
140 void remove_chars (int where, int len);
141 virtual bool isa (ClassType type)
142 { return (type == PTextClass ? TRUE : PNode::isa (type)); }
143 virtual char *symbol()
145 virtual void delete_self (delete_request_t);
147 protected: // variables
153 /* -------- PNumber -------- */
155 class PNumber : public PText {
157 PNumber (PNode *parent, PNode *previous, PNode *next, char *str = "#");
158 static const ClassType PNumberClass;
161 virtual bool isa (ClassType type)
162 { return (type == PNumberClass ? TRUE : PText::isa (type)); }
163 virtual const ClassType type ()
164 { return PNumberClass; }
166 protected: // variables
167 static const int f_precedence;
170 /* -------- PString -------- */
172 class PString : public PText {
174 static const ClassType PStringClass;
177 PString (char *str = "\"?\"");
178 PString (PNode *parent, PNode *previous, PNode *next, char *str = "\"?\"");
181 virtual bool isa (ClassType type)
182 { return (type == PStringClass ? TRUE : PText::isa (type)); }
183 virtual const ClassType type ()
184 { return PStringClass; }
186 protected: // variables
187 static const int f_precedence;
190 /* -------- PGroup -------- */
192 class PGroup : public PNode {
194 static const ClassType PGroupClass;
201 PGroup (PNode *parent, PNode *previous, PNode *next, PNode *subexpr);
204 virtual bool isa (ClassType type)
205 { return (type == PGroupClass ? TRUE : PNode::isa (type)); }
206 virtual const ClassType type ()
207 { return PGroupClass; }
208 virtual void replace_child (PNode *, PNode *replacement)
209 { f_subexpr = replacement;
210 if (replacement != NULL) replacement->f_parent = this; }
211 virtual const int precedence ()
212 { return f_precedence; }
213 virtual char *symbol ()
214 { return ("Group"); }
216 protected: // variables
217 static const int f_precedence;
220 /* -------- PRoot -------- */
221 /* root of a parse tree */
223 class PRoot : public PGroup {
225 static const ClassType PRootClass;
233 PRoot (PNode *subexpr);
236 virtual bool isa (ClassType type)
237 { return (type == PRootClass ? TRUE : PGroup::isa (type)); }
238 virtual const ClassType type ()
239 { return PRootClass; }
241 protected: // variables
243 PNode **f_node_of_real;
246 /* -------- PBooleanOp -------- */
248 class PBooleanOp : public PNode {
250 static const ClassType PBooleanOpClass;
257 virtual bool isa (ClassType type)
258 { return (type == PBooleanOpClass ? TRUE : PNode::isa (type)); }
259 virtual void replace_child (PNode *old, PNode *replacement);
260 static bool can_insert (PRoot *root, long position);
261 virtual void init (PRoot *, long pos);
262 virtual void delete_self (delete_request_t);
264 protected: // variables
267 /* -------- POr -------- */
269 class POr : public PBooleanOp {
271 static const ClassType POrClass;
273 PNotBoth *f_not_both;
276 POr (PRoot *root, long pos)
277 : f_not_both (NULL) { init (root, pos); }
278 virtual bool isa (ClassType type)
279 { return (type == POrClass ? TRUE : PBooleanOp::isa (type)); }
280 virtual const ClassType type ()
282 virtual char *symbol()
284 static void insert (PRoot *root, long pos);
285 virtual const int precedence ()
286 { return f_precedence; }
288 protected: // variables
289 static char *f_symbol;
290 static const int f_precedence;
293 /* -------- PAnd -------- */
295 class PAnd : public PBooleanOp {
297 static const ClassType PAndClass;
300 PAnd (PRoot *root, long pos)
301 { init (root, pos); }
302 virtual bool isa (ClassType type)
303 { return (type == PAndClass ? TRUE : PBooleanOp::isa (type)); }
304 virtual const ClassType type ()
305 { return PAndClass; }
306 virtual char *symbol()
308 static void insert (PRoot *root, long pos);
309 virtual const int precedence ()
310 { return f_precedence; }
312 protected: // variables
313 static char *f_symbol;
314 static const int f_precedence;
317 /* -------- PRelation -------- */
319 class PRelation : public PBooleanOp {
321 static const ClassType PRelationClass;
323 PPostfixOp *f_proximity;
327 : f_proximity (NULL) { }
328 virtual bool isa (ClassType type)
329 { return (type == PRelationClass ? TRUE : PBooleanOp::isa (type)); }
331 protected: // variables
334 /* -------- PNear -------- */
336 class PNear : public PRelation {
338 static const ClassType PNearClass;
341 PNear (PRoot *root, long pos)
342 { init (root, pos); }
343 virtual bool isa (ClassType type)
344 { return (type == PNearClass ? TRUE : PRelation::isa (type)); }
345 virtual const ClassType type ()
346 { return PNearClass; }
347 virtual char *symbol ()
349 static void insert (PRoot *root, long pos);
350 virtual const int precedence ()
351 { return f_precedence; }
353 protected: // variables
354 static char *f_symbol;
355 static const int f_precedence;
358 /* -------- PBefore -------- */
360 class PBefore : public PRelation {
362 static const ClassType PBeforeClass;
365 PBefore (PRoot *root, long pos)
366 { init (root, pos); }
367 virtual bool isa (ClassType type)
368 { return (type == PBeforeClass ? TRUE : PRelation::isa (type)); }
369 virtual const ClassType type ()
370 { return PBeforeClass; }
371 virtual char *symbol ()
373 static void insert (PRoot *root, long pos);
374 virtual const int precedence ()
375 { return f_precedence; }
377 protected: // variables
378 static char *f_symbol;
379 static const int f_precedence;
382 /* -------- PPrefixOp -------- */
384 class PPrefixOp : public PNode {
386 static const ClassType PPrefixOpClass;
391 PPrefixOp (PNode *rhs);
392 virtual bool isa (ClassType type)
393 { return (type == PPrefixOpClass ? TRUE : PNode::isa (type)); }
394 virtual void replace_child (PNode *, PNode *replacement)
395 { f_operand = replacement;
396 if (replacement != NULL) replacement->f_parent = this; }
399 /* -------- PNot -------- */
401 class PNot : public PPrefixOp {
403 static const ClassType PNotClass;
408 virtual bool isa (ClassType type)
409 { return (type == PNotClass ? TRUE : PPrefixOp::isa (type)); }
410 virtual const ClassType type ()
411 { return PNotClass; }
412 virtual char *symbol()
414 virtual const int precedence ()
415 { return f_precedence; }
416 static void insert (PRoot *root, long position);
417 static bool can_insert (PRoot *root, long position);
418 virtual void delete_self (delete_request_t request);
420 protected: // variables
421 static char *f_symbol;
422 static const int f_precedence;
426 /* -------- PPostfixOp -------- */
427 /* Postfix ops are bound by the thing they operation on. */
428 /* In other words, they can't apply to arbitrary things,
429 so the things they apply to will point to them. */
431 class PPostfixOp : public PNode {
433 static const ClassType PPostfixOpClass;
436 virtual bool isa (ClassType type)
437 { return (type == PPostfixOpClass ? TRUE : PNode::isa (type)); }
440 /* -------- PWeight -------- */
442 class PWeight : public PPostfixOp {
444 static const ClassType PWeightClass;
447 virtual bool isa (ClassType type)
448 { return (type == PWeightClass ? TRUE : PPostfixOp::isa (type)); }
449 virtual const ClassType type ()
450 { return PWeightClass; }
451 virtual char *symbol ()
453 static bool can_insert (PRoot *root, long position);
454 virtual const int precedence ()
455 { return f_precedence; }
457 protected: // variables
458 static char *f_symbol;
459 static const int f_precedence;
462 /* -------- PProximity -------- */
464 class PProximity : public PPostfixOp {
466 static const ClassType PProximityClass;
469 virtual bool isa (ClassType type)
470 { return (type == PProximityClass ? TRUE : PPostfixOp::isa (type)); }
471 virtual const ClassType type ()
472 { return PProximityClass; }
473 virtual char *symbol()
475 virtual const int precedence ()
476 { return f_precedence; }
478 protected: // variables
479 static char *f_symbol;
480 static const int f_precedence;
482 /* -------- PProximity -------- */
484 class PNotBoth : public PPostfixOp {
486 static const ClassType PNotBothClass;
489 virtual bool isa (ClassType type)
490 { return (type == PNotBothClass ? TRUE : PPostfixOp::isa (type)); }
491 virtual const ClassType type ()
492 { return PNotBothClass; }
493 virtual char *symbol()
495 virtual const int precedence ()
496 { return f_precedence; }
497 static bool can_insert (PRoot *root, int position);
499 protected: // variables
500 static char *f_symbol;
501 static const int f_precedence;
504 #endif /* _ParseTree_hh */
505 /* DO NOT ADD ANY LINES AFTER THIS #endif */