1 //////////////////////////////////////////////////////////////////////////////
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
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
18 // This software is still under development and we welcome(read crave for)
19 // any suggestions and help from the users.
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
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
60 ///////////////////////////////////////////////////////////////////////////
63 Node(const Node
&); // no copy constructor
64 void operator = (const Node
&); // no assignment
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.
83 ///////////////////////////////////////////////////////////////////////////
84 // Constructors and destructor
85 ///////////////////////////////////////////////////////////////////////////
87 GLA( const Grammar
&, Mem
& );
90 ///////////////////////////////////////////////////////////////////////////
91 // Method to construct the LR(0) automaton and compute the GLA
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
);