initial
[prop.git] / include / AD / automata / topdowng.h
blobb55c27af16748cfb38b872e249c27a31721250ef
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 free 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 any suggestions
19 // and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef top_down_tree_matching_automata_generator_h
26 #define top_down_tree_matching_automata_generator_h
28 #include <AD/automata/acgen.h> // Aho-Corasick string matching generator
29 #include <AD/automata/treegram.h> // Tree grammars
31 //////////////////////////////////////////////////////////////////////////////
33 // The top-down tree matching algorithm\cite{tree-matching, AC}
34 // reduces the problem of tree matching to the problem of string matching
35 // a set of path strings.
37 //////////////////////////////////////////////////////////////////////////////
39 class TopDownGen : public ACGen {
41 TopDownGen(const TopDownGen&); // no copy constructor
42 void operator = (const TopDownGen&); // no assignment
44 public:
46 ///////////////////////////////////////////////////////////////////////////
47 // Inherit some types
48 ///////////////////////////////////////////////////////////////////////////
49 typedef ACGen Super;
50 typedef Super::Symbol Symbol;
51 typedef Super::Rule Rule;
52 typedef Super::Offset Offset;
53 typedef Super::State State;
54 typedef TreeGrammar::TreeProduction TreeProduction;
56 private:
57 ///////////////////////////////////////////////////////////////////////////
58 // The current tree grammar
59 ///////////////////////////////////////////////////////////////////////////
60 const TreeGrammar * G;
62 ///////////////////////////////////////////////////////////////////////////
63 // Private method to add a path string to the trie
64 ///////////////////////////////////////////////////////////////////////////
65 void add_path(int, const TreeTerm, int, Symbol []);
67 public:
69 ///////////////////////////////////////////////////////////////////////////
70 // Constructors and destructor
71 ///////////////////////////////////////////////////////////////////////////
72 TopDownGen();
73 TopDownGen(const TreeGrammar&);
74 ~TopDownGen();
76 ///////////////////////////////////////////////////////////////////////////
77 // Selectors
78 ///////////////////////////////////////////////////////////////////////////
79 inline int size() const { return Super::size(); }
80 inline State start_state() const { return 0; }
82 ///////////////////////////////////////////////////////////////////////////
83 // Compilation and code emission
84 ///////////////////////////////////////////////////////////////////////////
85 void compile (const TreeGrammar&);
86 virtual ostream& gen_code (ostream&, const char name[]) const;
87 virtual ostream& print_report (ostream&) const;
89 ///////////////////////////////////////////////////////////////////////////
90 // Advance one state within the tree matching automaton
91 ///////////////////////////////////////////////////////////////////////////
92 inline State go (register State s, register int branch, register Symbol c) const
93 { return Super::go( Super::go(s,branch), c); }
96 #endif