initial
[prop.git] / include / AD / automata / gla.h
blobed289834e1a32487f956fbddc80d1cb53ddf5803
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are welcomed to incorporate any part of ADLib and Prop into
9 // your programs.
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
16 // code.
18 // This software is still under development and we welcome(read crave for)
19 // any suggestions and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef general_lookahead_automata_h
26 #define general_lookahead_automata_h
28 #include <AD/automata/grammar.h> // grammars
29 #include <AD/memory/mem.h> // memory manager
30 #include <AD/contain/bitset.h> // bit sets
32 //////////////////////////////////////////////////////////////////////////////
33 // Class GLA represents a ``general_lookahead_automaton'' (see Terrance
34 // Parr's PhD thesis at Purdue U.)
35 //////////////////////////////////////////////////////////////////////////////
36 class GLA : public DFATables {
38 GLA(const GLA&); // no copy constructor
39 void operator = (const GLA&); // no assignment
41 public:
43 ///////////////////////////////////////////////////////////////////////////
44 // Import some types from superclass.
45 ///////////////////////////////////////////////////////////////////////////
46 typedef DFATables Super;
47 typedef Super::State State;
48 typedef Super::Rule Rule;
49 typedef Super::Symbol Symbol;
50 typedef Grammar::NonTerminal NonTerminal;
51 typedef Grammar::Terminal Terminal;
52 typedef Grammar::EquivMap EquivMap;
53 typedef BitSet NonTerminalSet;
55 ///////////////////////////////////////////////////////////////////////////
56 // Define the GLA internals:
57 // A GLA node is represented by the following class.
58 // It is basically a labeled graph represented in child-sibling
59 // format.
60 ///////////////////////////////////////////////////////////////////////////
61 class Node {
63 Node(const Node&); // no copy constructor
64 void operator = (const Node&); // no assignment
66 public:
68 Node();
69 ~Node();
72 protected:
74 ///////////////////////////////////////////////////////////////////////////
75 // The internals of this class is hidden.
76 ///////////////////////////////////////////////////////////////////////////
77 Mem& mem; // internal memory manager
78 class GLA_Impl * intern; // internal rep.
79 virtual void clean_up(); // method to clean up internal rep.
81 public:
83 ///////////////////////////////////////////////////////////////////////////
84 // Constructors and destructor
85 ///////////////////////////////////////////////////////////////////////////
86 GLA( Mem& );
87 GLA( const Grammar&, Mem& );
88 virtual ~GLA();
90 ///////////////////////////////////////////////////////////////////////////
91 // Method to construct the LR(0) automaton and compute the GLA
92 // from the grammar.
93 ///////////////////////////////////////////////////////////////////////////
94 virtual void build(const Grammar&);
96 ///////////////////////////////////////////////////////////////////////////
97 // Operations on a GLA:
98 // `look()' -- compute the linear lookahead approximation from a
99 // node of the GLA, where 'k' is the lookahead count.
100 ///////////////////////////////////////////////////////////////////////////
101 const NonTerminalSet& look (const Node *, int k);
103 ///////////////////////////////////////////////////////////////////////////
104 // Method to print a report.
105 ///////////////////////////////////////////////////////////////////////////
106 virtual ostream& print_report(ostream&, Bool, Bool);
109 #endif