comparison anagram/agcore/rule.h @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children 607e3be6bad8
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /*
2 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * rule.h
7 */
8
9 #ifndef RULE_H
10 #define RULE_H
11
12 class AgStringDictionary; // from agdict.h
13 #include "agstring.h"
14 #include "register.h"
15
16
17 struct RuleDescriptor; // below
18 class Token; // from token.h (included below)
19
20 extern AgStringDictionary cVariableList;
21
22 class Rule : public ObjectRegister<RuleDescriptor> {
23 public:
24 Rule();// {}
25 Rule(int x);
26 Rule(const Rule &t);
27 Token &token(int) const;
28
29 static Rule create();
30 static void reset();
31 static const int first;
32
33 class Map;
34 friend class Map;
35
36 class Map {
37 public:
38 RuleDescriptor &operator [] (unsigned x);
39 };
40 };
41
42 class CastDescriptor {
43 public:
44 AgString name;
45 int wrapper : 1;
46
47 CastDescriptor();
48 CastDescriptor(const char *s);
49 int operator < (const CastDescriptor &c) const { return name < c.name; }
50 char *pointer() { return name.pointer(); }
51 };
52
53 class Cast : public KeyedObjectRegister<CastDescriptor> {
54 public:
55 Cast();
56 Cast(const int x);
57 Cast(const char *);
58 Cast(const AgString);
59
60 static const int first;
61
62 static void reset();
63 static Cast create();
64
65 AgString &name() { return descriptor->name; }
66 int operator < (const Cast x) const;
67
68 static Cast voidCast;
69 static Cast intCast;
70 static Cast longCast;
71 static int nWrappers;
72
73 void requireWrapper();
74 int wrapperRequired();
75 };
76
77 #include "token.h"
78
79 class RuleElement {
80 public:
81 Token token;
82 int cVariable;
83
84 RuleElement() {}
85 RuleElement(const Token &t, int x);
86 int operator < (const RuleElement) const;
87 };
88
89 struct RuleDescriptor {
90 Token prim_tkn;
91 unsigned line, col;
92 unsigned proc_name;
93 AgArray<RuleElement> elementList;
94 AgArray<RuleElement> hostElementList; // for immmediate actions only
95 unsigned
96 non_vanishing_length,
97 op_bias;
98 unsigned precedence_level;
99 unsigned not_unique_reduction : 1;
100 unsigned error_mask: 1;
101 unsigned left_associative: 1;
102 unsigned right_associative: 1;
103 unsigned fast_loop: 1;
104 unsigned immediate_proc: 1;
105 unsigned lexical: 1;
106 unsigned nonLexical: 1;
107 unsigned reductionRequired: 1;
108
109 unsigned length() { return elementList.size(); }
110 RuleDescriptor();
111 int operator < (const RuleDescriptor &d) const {
112 return elementList < d.elementList;
113 }
114 Token &token(int);
115 };
116
117 extern Rule::Map map_form_number;
118
119 struct VpRuleDescriptor {
120 AgArray<RuleElement> elementList;
121 unsigned procedureName;
122
123 VpRuleDescriptor();
124 VpRuleDescriptor(AgStack<RuleElement> &, int pn);
125 int operator < (const VpRuleDescriptor x) const;
126 };
127
128 class VpRule : public KeyedObjectRegister<VpRuleDescriptor> {
129 public:
130 VpRule();
131 VpRule(const int x);
132 VpRule(const VpRule &x);
133 VpRule(AgStack<RuleElement> &, int pn);
134
135 static const int first;
136
137 static void reset();
138 static VpRule create();
139 };
140
141
142 #endif /* RULE_H */