Further work on AST transformation
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
48
include/DeleteTransformation.h
Normal file
48
include/DeleteTransformation.h
Normal 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;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user