VICI  0.11.815
Visual Chart Interpreter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
parseTree.h
Go to the documentation of this file.
1 /*
2  * parseTree.h
3  *
4  * Copyright 2012 - 2014 Brenton Ross
5  *
6  * This file is part of VICI.
7  *
8  * VICI is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * VICI is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with VICI. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
28 #ifndef VICI_PARSETREE_H
29 #define VICI_PARSETREE_H
30 
31 #include "vici.h"
32 #include <vici/xml.h>
33 #include <map>
34 
35 namespace VICI
36 {
37 
39 
47 class EbnfNode
48 {
49 public:
51  enum NodeType {
57  Name,
62  };
63 
64 private:
65  static std::map< NodeType, std::string > nodeNames;
66 public:
67  EbnfNode();
68  ~EbnfNode();
69 
72  *next;
74  *lastChild;
75 
77  std::string text;
78 
80 
83  std::string typeOfNode() const;
84 
86 
89  void typeOfNode( const std::string &t );
90 
91 };
92 
94 
102 class EbnfTree : public EBNF::ParseTree
103 {
104 public:
105  EbnfTree();
106  virtual ~EbnfTree();
107 
109 
111 
114  void exportXml(const Path &p);
115 
117 
120  void importXml(const Path &p);
121 };
122 
124 
133 class EbnfXml : public VICI::cfi::Xml
134 {
135 private:
136  void exportNode( EbnfNode *, xmlNodePtr ); // recursive
137  void importNode( EbnfNode *, xmlNodePtr ); // recursive
138 
139 public:
140  EbnfXml();
141 
143 
147  void exportTree( EbnfTree *tree, const Path &path );
148 
150 
154  void importTree( EbnfTree *tree, const Path &path );
155 };
156 
157 } // end namespace VICI
158 #endif /* PARSETREE_H_ */
A node of the EBNF parse tree.
Definition: parseTree.h:47
has no children
Definition: parseTree.h:57
NodeType nodeType
defines what EBNF non-terminal the node represents
Definition: parseTree.h:76
void importXml(const Path &p)
Load the tree from an XML file.
Definition: parseTree.cpp:123
EbnfNode * lastChild
pointer to last child node
Definition: parseTree.h:73
A specialization of the Xml class for the parse tree.
Definition: parseTree.h:133
EbnfNode * firstChild
pointer to first child node
Definition: parseTree.h:73
has no children
Definition: parseTree.h:56
can have any number of children
Definition: parseTree.h:58
void importTree(EbnfTree *tree, const Path &path)
import a tree from parse-tree.xml
Definition: parseTree.cpp:144
EbnfNode()
Constructor.
Definition: parseTree.cpp:38
EbnfNode * next
pointer to next sibling node
Definition: parseTree.h:71
has two children
Definition: parseTree.h:61
one for each production. Can have any number of child nodes. firstChild is the Name of the Production...
Definition: parseTree.h:54
A type for the parsed form of EBNF.
Definition: vici.h:226
just until we load something sensible.
Definition: parseTree.h:52
std::string typeOfNode() const
get the type of the node
Definition: parseTree.cpp:76
EbnfNode * parent
pointer to parent node
Definition: parseTree.h:70
virtual ~EbnfTree()
destructor
Definition: parseTree.cpp:105
Manipulate path strings.
Definition: stringy.h:74
NodeType
the type of node, which corresponds to the non-terminals of the EBNF for EBNF.
Definition: parseTree.h:51
void exportTree(EbnfTree *tree, const Path &path)
export the tree to parse-tree.xml
Definition: parseTree.cpp:136
EbnfNode * prev
pointer to previous sibling node
Definition: parseTree.h:71
Project wide declarations and definitions.
one or two children of type Quotation. firstChild == lastChild if only one child. ...
Definition: parseTree.h:55
An implementation of the ParseTree type.
Definition: parseTree.h:102
can have any number of children
Definition: parseTree.h:60
~EbnfNode()
Destructor.
Definition: parseTree.cpp:61
EbnfXml()
constructor
Definition: parseTree.cpp:131
void exportXml(const Path &p)
Save the tree as an XML file.
Definition: parseTree.cpp:114
EbnfNode * root
root node of the tree - type is Grammar
Definition: parseTree.h:108
A C++ wrapper for libxml2.
Definition: xml.h:73
std::string text
the terminal leaves of the EBNF
Definition: parseTree.h:77
can have any number of children
Definition: parseTree.h:59
EbnfTree()
constructor
Definition: parseTree.cpp:97
the root of the tree - only one of these.
Definition: parseTree.h:53