Further work on AST transformation

This commit is contained in:
Nathan Braswell
2013-10-16 01:43:18 -04:00
parent b9ffe33d0b
commit 02fd878c92
9 changed files with 195 additions and 5 deletions

View File

@@ -18,10 +18,14 @@ enum ValueType {none, boolean, integer, floating, double_percision, char_string
class ASTData {
public:
ASTData();
ASTData(ASTType type, ValueType valueType = none);
ASTData(ASTType type, Symbol symbol, ValueType valueType = none);
~ASTData();
std::string toString();
static std::string ASTTypeToString(ASTType type);
static std::string ValueTypeToString(ValueType type);
static ValueType strToType(std::string type);
ASTType type;
ValueType valueType;
Symbol symbol;

View File

@@ -9,6 +9,7 @@ class ASTTransformation: public NodeTransformation<Symbol,ASTData> {
ASTTransformation();
~ASTTransformation();
virtual NodeTree<ASTData>* transform(NodeTree<Symbol>* from);
std::string concatSymbolTree(NodeTree<Symbol>* root);
private:
//Nothing

View File

@@ -0,0 +1,48 @@
#ifndef DELETETRANSFORMATION_H
#define DELETETRANSFORMATION_H
#include <queue>
#include <vector>
#include "NodeTransformation.h"
template<class T>
class DeleteTransformation: public NodeTransformation<T,T> {
public:
DeleteTransformation(T toDelete);
~DeleteTransformation();
virtual NodeTree<T>* transform(NodeTree<T>* from);
private:
T toRemove;
};
#endif
template<class T>
DeleteTransformation<T>::DeleteTransformation(T toRemove) {
this->toRemove = toRemove;
}
template<class T>
DeleteTransformation<T>::~DeleteTransformation() {
//
}
template<class T>
NodeTree<T>* DeleteTransformation<T>::transform(NodeTree<T>* from) {
std::queue<NodeTree<T>*> toProcess;
toProcess.push(from);
while(!toProcess.empty()) {
NodeTree<T>* node = toProcess.front();
toProcess.pop();
std::vector<NodeTree<T>*> children = node->getChildren();
for (int i = 0; i < children.size(); i++) {
if (children[i]->getData() == toRemove)
node->removeChild(children[i]);
else
toProcess.push(children[i]);
}
}
return from;
}

View File

@@ -22,6 +22,7 @@ class Symbol {
bool const operator<(const Symbol &other)const;
std::string getName() const;
std::string getValue() const;
std::string toString() const;
Symbol clone();
void setSubTree(NodeTree<Symbol>* tree);