ignore .lib and .exe
[prop.git] / prop-src / parsegen.h
blob29330fdd79d3c2a9d5f6ceea906696a67c6edab0
1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.6),
3 // last updated on Nov 2, 1999.
4 // The original source file is "parsegen.ph".
5 ///////////////////////////////////////////////////////////////////////////////
7 #line 1 "parsegen.ph"
8 ///////////////////////////////////////////////////////////////////////////////
9 //
10 // This file contains the definitions used in the parser generator
11 // and meta syntax compiler.
13 ///////////////////////////////////////////////////////////////////////////////
14 #ifndef parser_generator_h
15 #define parser_generator_h
17 #include <AD/automata/grammar.h>
18 #include "basics.h"
19 #include "ir.h"
20 #include "codegen.h"
21 #include "classdef.h"
23 ///////////////////////////////////////////////////////////////////////////////
25 // Forward declarations
27 ///////////////////////////////////////////////////////////////////////////////
28 class Grammar; // grammar class
29 class LALR1Gen; // lalr1 parser class
30 class OpPrecedence; // operator precedence class
32 #line 25 "parsegen.ph"
33 #line 71 "parsegen.ph"
34 ///////////////////////////////////////////////////////////////////////////////
36 // Forward class definition for Exp
38 ///////////////////////////////////////////////////////////////////////////////
39 #ifndef datatype_Exp_defined
40 #define datatype_Exp_defined
41 class a_Exp;
42 typedef a_Exp * Exp;
43 #endif
45 ///////////////////////////////////////////////////////////////////////////////
47 // Forward class definition for Decl
49 ///////////////////////////////////////////////////////////////////////////////
50 #ifndef datatype_Decl_defined
51 #define datatype_Decl_defined
52 class a_Decl;
53 typedef a_Decl * Decl;
54 #endif
56 ///////////////////////////////////////////////////////////////////////////////
58 // Forward class definition for GramExp
60 ///////////////////////////////////////////////////////////////////////////////
61 #ifndef datatype_GramExp_defined
62 #define datatype_GramExp_defined
63 class a_GramExp;
64 typedef a_GramExp * GramExp;
65 #endif
67 ///////////////////////////////////////////////////////////////////////////////
69 // Forward class definition for BNF
71 ///////////////////////////////////////////////////////////////////////////////
72 #ifndef datatype_BNF_defined
73 #define datatype_BNF_defined
74 class a_BNF;
75 typedef a_BNF * BNF;
76 #endif
78 ///////////////////////////////////////////////////////////////////////////////
80 // Forward class definition for PrecRule
82 ///////////////////////////////////////////////////////////////////////////////
83 #ifndef datatype_PrecRule_defined
84 #define datatype_PrecRule_defined
85 class a_PrecRule;
86 typedef a_PrecRule * PrecRule;
87 #endif
89 enum PrecMode {
90 LEFTassoc = 0, RIGHTassoc = 1, NONassoc = 2
95 ///////////////////////////////////////////////////////////////////////////////
96 // Definition of type ProductionSymbols
97 ///////////////////////////////////////////////////////////////////////////////
98 #line 66 "parsegen.ph"
99 typedef a_List<ProductionSymbol> * ProductionSymbols;
101 ///////////////////////////////////////////////////////////////////////////////
102 // Definition of type PrecRules
103 ///////////////////////////////////////////////////////////////////////////////
104 #line 67 "parsegen.ph"
105 typedef a_List<PrecRule> * PrecRules;
107 ///////////////////////////////////////////////////////////////////////////////
108 // Definition of type BNFs
109 ///////////////////////////////////////////////////////////////////////////////
110 #line 68 "parsegen.ph"
111 typedef a_List<BNF> * BNFs;
113 ///////////////////////////////////////////////////////////////////////////////
114 // Definition of type GramExps
115 ///////////////////////////////////////////////////////////////////////////////
116 #line 69 "parsegen.ph"
117 typedef a_List<GramExp> * GramExps;
119 ///////////////////////////////////////////////////////////////////////////////
120 // Definition of type ShiftReduceErrors
121 ///////////////////////////////////////////////////////////////////////////////
122 #line 70 "parsegen.ph"
123 typedef int ShiftReduceErrors;
125 ///////////////////////////////////////////////////////////////////////////////
127 // Base class for datatype GramExp
129 ///////////////////////////////////////////////////////////////////////////////
130 class a_GramExp : public Loc {
131 public:
132 enum Tag_GramExp {
133 tag_EXPgram = 0, tag_POLYgram = 1, tag_UNIONgram = 2,
134 tag_RESTRICTgram = 3, tag_APPgram = 4
137 public:
138 const Tag_GramExp tag__; // variant tag
139 protected:
140 inline a_GramExp(Tag_GramExp t__) : tag__(t__) {}
141 public:
143 inline int boxed(const a_GramExp *) { return 1; }
144 inline int untag(const a_GramExp * x) { return x->tag__; }
145 ///////////////////////////////////////////////////////////////////////////////
147 // Class for datatype constructor GramExp::EXPgram
149 ///////////////////////////////////////////////////////////////////////////////
150 class GramExp_EXPgram : public a_GramExp {
151 public:
152 #line 33 "parsegen.ph"
153 a_List<PrecRule> * _1; ShiftReduceErrors _2; a_List<BNF> * _3;
154 GramExp_EXPgram (a_List<PrecRule> * x_1, ShiftReduceErrors x_2, a_List<BNF> * x_3);
157 ///////////////////////////////////////////////////////////////////////////////
159 // Class for datatype constructor GramExp::POLYgram
161 ///////////////////////////////////////////////////////////////////////////////
162 class GramExp_POLYgram : public a_GramExp {
163 public:
164 #line 35 "parsegen.ph"
165 int _1; Id * _2; GramExp _3;
166 GramExp_POLYgram (int x_1, Id * x_2, GramExp x_3);
169 ///////////////////////////////////////////////////////////////////////////////
171 // Class for datatype constructor GramExp::UNIONgram
173 ///////////////////////////////////////////////////////////////////////////////
174 class GramExp_UNIONgram : public a_GramExp {
175 public:
176 #line 36 "parsegen.ph"
177 GramExp _1; GramExp _2;
178 GramExp_UNIONgram (GramExp x_1, GramExp x_2);
181 ///////////////////////////////////////////////////////////////////////////////
183 // Class for datatype constructor GramExp::RESTRICTgram
185 ///////////////////////////////////////////////////////////////////////////////
186 class GramExp_RESTRICTgram : public a_GramExp {
187 public:
188 #line 37 "parsegen.ph"
189 GramExp RESTRICTgram;
190 GramExp_RESTRICTgram (GramExp x_RESTRICTgram);
193 ///////////////////////////////////////////////////////////////////////////////
195 // Class for datatype constructor GramExp::APPgram
197 ///////////////////////////////////////////////////////////////////////////////
198 class GramExp_APPgram : public a_GramExp {
199 public:
200 #line 38 "parsegen.ph"
201 GramExp _1; GramExp _2;
202 GramExp_APPgram (GramExp x_1, GramExp x_2);
205 ///////////////////////////////////////////////////////////////////////////////
207 // Datatype constructor functions for GramExp
209 ///////////////////////////////////////////////////////////////////////////////
210 extern a_GramExp * EXPgram (a_List<PrecRule> * x_1, ShiftReduceErrors x_2, a_List<BNF> * x_3);
211 extern a_GramExp * POLYgram (int x_1, Id * x_2, GramExp x_3);
212 extern a_GramExp * UNIONgram (GramExp x_1, GramExp x_2);
213 extern a_GramExp * RESTRICTgram (GramExp x_RESTRICTgram);
214 extern a_GramExp * APPgram (GramExp x_1, GramExp x_2);
216 ///////////////////////////////////////////////////////////////////////////////
218 // Class for datatype constructor BNF::BNFrule
220 ///////////////////////////////////////////////////////////////////////////////
221 class a_BNF : public Loc {
222 public:
223 #line 45 "parsegen.ph"
224 Id _1; Ty _2; a_List<ProductionSymbols> * _3;
225 a_BNF (Id x_1, Ty x_2, a_List<ProductionSymbols> * x_3);
227 inline int boxed(const a_BNF *) { return 1; }
228 inline int untag(const a_BNF *) { return 0; }
229 ///////////////////////////////////////////////////////////////////////////////
231 // Datatype constructor functions for BNF
233 ///////////////////////////////////////////////////////////////////////////////
234 extern a_BNF * BNFrule (Id x_1, Ty x_2, a_List<ProductionSymbols> * x_3);
236 ///////////////////////////////////////////////////////////////////////////////
238 // Class for datatype constructor PrecRule::PRECrule
240 ///////////////////////////////////////////////////////////////////////////////
241 class a_PrecRule : public Loc {
242 public:
243 #line 52 "parsegen.ph"
244 PrecMode _1; int _2; ProductionSymbols _3;
245 a_PrecRule (PrecMode x_1, int x_2, ProductionSymbols x_3);
247 inline int boxed(const a_PrecRule *) { return 1; }
248 inline int untag(const a_PrecRule *) { return 0; }
249 ///////////////////////////////////////////////////////////////////////////////
251 // Datatype constructor functions for PrecRule
253 ///////////////////////////////////////////////////////////////////////////////
254 extern a_PrecRule * PRECrule (PrecMode x_1, int x_2, ProductionSymbols x_3);
257 #line 71 "parsegen.ph"
258 #line 71 "parsegen.ph"
261 ///////////////////////////////////////////////////////////////////////////////
263 // Pretty printing methods.
265 ///////////////////////////////////////////////////////////////////////////////
266 extern std::ostream& operator << (std::ostream&, ProductionSymbol);
267 extern std::ostream& operator << (std::ostream&, ProductionSymbols);
268 extern std::ostream& operator << (std::ostream&, PrecRule);
269 extern std::ostream& operator << (std::ostream&, PrecRules);
270 extern std::ostream& operator << (std::ostream&, BNF);
271 extern std::ostream& operator << (std::ostream&, BNFs);
272 extern std::ostream& operator << (std::ostream&, GramExp);
273 extern std::ostream& operator << (std::ostream&, GramExps);
275 ///////////////////////////////////////////////////////////////////////////////
277 // Class to represent a syntax class
279 ///////////////////////////////////////////////////////////////////////////////
280 class SyntaxClass : public ClassDefinition
281 { SyntaxClass(const SyntaxClass&);
282 void operator = (const SyntaxClass&);
284 public:
286 typedef Grammar::Terminal Terminal;
287 typedef Grammar::NonTerminal NonTerminal;
288 typedef Grammar::Action Action;
289 typedef Grammar::Production Production;
291 protected:
293 ////////////////////////////////////////////////////////////////////////////
295 // Internal data for generating a parser
297 ////////////////////////////////////////////////////////////////////////////
298 BNFs production_rules; // production rules
299 PrecRules precedence_rules; // precedence rules
300 Production * productions; // products array
301 Grammar * G; // Grammar object
302 LALR1Gen * parserGen; // Parser generator object
303 OpPrecedence * prec; // operator precedence object
304 int number_of_productions; // Number of productions
305 HashTable nonterm_map; // map nonterm -> Nonterminal
306 HashTable action_map; // map Action -> Decls
307 HashTable inner_action_map; //
308 HashTable line_map; // map Action -> line#
309 HashTable predicate_map; // ??
310 Terminal min_term; // min Terminal #
311 Terminal max_term; // max Terminal #
312 Terminal error_term; // error Terminal #
313 NonTerminal max_nonterm; // max NonTerminal #
314 NonTerminal start_symbol; // start symbol of grammar
315 Action min_action; // min Action #
316 Id * symbol_names; // map NonTerminal -> Id
317 Ty * ty_map; // map NonTerminal -> Ty
320 public:
321 SyntaxClass(CLASS_TYPE, Id, Inherits, TyQual, Decls);
322 ~SyntaxClass();
324 ////////////////////////////////////////////////////////////////////////////
326 // Methods to generate a syntax class
328 ////////////////////////////////////////////////////////////////////////////
329 virtual void gen_parser (CodeGen&, GramExp);
330 virtual void gen_class_interface(CodeGen&);
331 virtual void gen_class_implementation(CodeGen&, Tys, DefKind);
333 private:
334 // compile a set of rules
335 virtual void compile_rules (CodeGen&, PrecRules, ShiftReduceErrors, BNFs);
336 // compile a grammar expression
337 virtual void compile_grammar (CodeGen&, GramExp);
339 // Various phases of the compilation process
340 void initialize();
341 void cleanup();
342 void preprocess_grammar();
343 void translate_into_grammar();
344 void define_operator_precedence();
345 void process_parser_errors(ShiftReduceErrors);
347 // Various phases of the code generation process
348 void generate_semantic_stack_definition(CodeGen&);
349 void generate_semantic_stack_growth(CodeGen&);
350 void generate_semantic_stack_adjustment(CodeGen&);
351 void generate_debugging_tables(CodeGen&);
352 void generate_parse_method(CodeGen&);
353 void generate_parser_tables(CodeGen&);
354 void generate_action_driver(CodeGen&);
355 virtual void generate_semantic_actions(CodeGen&);
357 virtual void gen_class_constructor_initializers(CodeGen&, Tys, DefKind);
360 ///////////////////////////////////////////////////////////////////////////////
362 // Definition of the parser generator
364 ///////////////////////////////////////////////////////////////////////////////
365 class ParserCompiler : virtual public CodeGen {
367 ParserCompiler(const ParserCompiler&); // no copy constructor
368 void operator = (const ParserCompiler&); // no assignment
370 public:
371 ParserCompiler();
372 ~ParserCompiler();
374 ////////////////////////////////////////////////////////////////////////////
375 // Method to generate a syntax class
376 ////////////////////////////////////////////////////////////////////////////
377 virtual void gen_parser (Id, GramExp);
380 #endif
381 #line 193 "parsegen.ph"
383 ------------------------------- Statistics -------------------------------
384 Merge matching rules = yes
385 Number of DFA nodes merged = 0
386 Number of ifs generated = 0
387 Number of switches generated = 0
388 Number of labels = 0
389 Number of gotos = 0
390 Adaptive matching = enabled
391 Fast string matching = disabled
392 Inline downcasts = enabled
393 --------------------------------------------------------------------------