.gitignore
[prop.git] / lib-src / rewrite / twig.cc
blobe03a8a491de5d038e9cb47e50eabc4c91edecbca
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 //////////////////////////////////////////////////////////////////////////////
26 // This file contains the implementation of a top-down tree parser
27 // with dynamic programming. See Aho, Tsiang, et al. for details.
28 //////////////////////////////////////////////////////////////////////////////
30 #include <iostream>
31 #include <AD/rewrite/twig.h> // twig module
32 #include <AD/memory/boundtag.h> // boundary tag memory maager
33 #include <AD/contain/bitset.h> // bit sets
35 //////////////////////////////////////////////////////////////////////////////
36 // Make hidden types visible
37 //////////////////////////////////////////////////////////////////////////////
38 typedef Twig::Symbol Symbol;
39 typedef Twig::State State;
40 typedef Twig::Offset Offset;
41 typedef Twig::Rule Rule;
43 //////////////////////////////////////////////////////////////////////////////
44 // Internal representation of the tree matcher
45 //////////////////////////////////////////////////////////////////////////////
46 class Twig_Impl {
47 public:
48 Twig_Impl() {}
49 ~Twig_Impl() {}
52 //////////////////////////////////////////////////////////////////////////////
53 // Constructor and destructor for class Twig.
54 //////////////////////////////////////////////////////////////////////////////
55 Twig:: Twig( const Offset base_table [],
56 const State check_table [],
57 const State failure [],
58 const State next_table [],
59 const Rule rule_table []
60 ) :
61 Super(base_table,check_table,failure,next_table,rule_table),
62 mem(* new BoundaryTag) {}
63 Twig::~Twig() { close(); delete (&mem); }
65 //////////////////////////////////////////////////////////////////////////////
66 // Method to initialize the tree reducer.
67 //////////////////////////////////////////////////////////////////////////////
68 void Twig::open()
69 { if (impl) delete impl;
70 impl = new Twig_Impl();
73 //////////////////////////////////////////////////////////////////////////////
74 // Method to clean up the tree reducer.
75 //////////////////////////////////////////////////////////////////////////////
76 void Twig::close()
77 { if (impl) delete impl; impl = 0; }
79 //////////////////////////////////////////////////////////////////////////////
80 // Method to perform the actual reduction.
81 //////////////////////////////////////////////////////////////////////////////
82 void Twig::reduce()