Lot's of work on a CGenerator, AST and language improvements
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
enum ASTType {undef, translation_unit, interpreter_directive, import, identifier,
|
||||
function, code_block,
|
||||
typed_parameter, expression, boolean_expression, statement,
|
||||
if_statement, return_statement, assignment_statement, function_call,
|
||||
value};
|
||||
if_statement, return_statement, assignment_statement, declaration_statement,
|
||||
function_call, value};
|
||||
enum ValueType {none, boolean, integer, floating, double_percision, char_string };
|
||||
|
||||
|
||||
|
||||
21
include/CGenerator.h
Normal file
21
include/CGenerator.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef CGENERATOR_H
|
||||
#define CGENERATOR_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "NodeTree.h"
|
||||
#include "ASTData.h"
|
||||
|
||||
|
||||
class CGenerator {
|
||||
public:
|
||||
CGenerator();
|
||||
~CGenerator();
|
||||
std::string generate(NodeTree<ASTData>* from);
|
||||
static std::string ValueTypeToCType(ValueType type);
|
||||
private:
|
||||
std::string tabs();
|
||||
int tabLevel;
|
||||
};
|
||||
#endif
|
||||
@@ -41,10 +41,8 @@ NodeTree<T>* CollapseTransformation<T>::transform(NodeTree<T>* from) {
|
||||
if (children[i]->getData() == toCollapse) {
|
||||
node->removeChild(children[i]);
|
||||
std::vector<NodeTree<T>*> newChildren = children[i]->getChildren();
|
||||
node->addChildren(newChildren);
|
||||
node->insertChildren(i,newChildren);
|
||||
toProcess.push(node); //Do this node again
|
||||
// for (int j = 0; j < newChildren.size(); j++)
|
||||
// toProcess.push(newChildren[j]);
|
||||
}
|
||||
else
|
||||
toProcess.push(children[i]);
|
||||
|
||||
@@ -27,8 +27,11 @@ class NodeTree {
|
||||
std::vector<NodeTree<T>*> getParents();
|
||||
|
||||
void addChild(NodeTree<T>* child);
|
||||
void insertChild(int i, NodeTree<T>* child);
|
||||
void addChildren(std::vector<NodeTree<T>*>* children);
|
||||
void addChildren(std::vector<NodeTree<T>*> children);
|
||||
void insertChildren(int index, std::vector<NodeTree<T>*>* children);
|
||||
void insertChildren(int index, std::vector<NodeTree<T>*> children);
|
||||
int findChild(NodeTree<T>* child);
|
||||
void removeChild(NodeTree<T>* child);
|
||||
void removeChild(int index);
|
||||
@@ -40,6 +43,7 @@ class NodeTree {
|
||||
void setName(std::string);
|
||||
|
||||
T getData() const;
|
||||
T* getDataRef();
|
||||
void setData(T data);
|
||||
|
||||
int size();
|
||||
@@ -130,6 +134,14 @@ void NodeTree<T>::addChild(NodeTree<T>* child) {
|
||||
children.push_back(child);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void NodeTree<T>::insertChild(int i, NodeTree<T>* child) {
|
||||
if (!child)
|
||||
throw "Help, NULL child";
|
||||
if (findChild(child) == -1)
|
||||
children.insert(children.begin()+i,child);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void NodeTree<T>::addChildren(std::vector<NodeTree<T>*>* children) {
|
||||
for (typename std::vector<NodeTree<T>*>::size_type i = 0; i < children->size(); i++)
|
||||
@@ -142,6 +154,18 @@ void NodeTree<T>::addChildren(std::vector<NodeTree<T>*> children) {
|
||||
addChild(children[i]);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void NodeTree<T>::insertChildren(int index, std::vector<NodeTree<T>*>* children) {
|
||||
for (typename std::vector<NodeTree<T>*>::size_type i = 0; i < children->size(); i++)
|
||||
insertChild(index+i,(*children)[i]);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void NodeTree<T>::insertChildren(int index, std::vector<NodeTree<T>*> children) {
|
||||
for (typename std::vector<NodeTree<T>*>::size_type i = 0; i < children.size(); i++)
|
||||
insertChild(index+i, children[i]);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
int NodeTree<T>::findChild(NodeTree<T>* child) {
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
@@ -207,6 +231,11 @@ T NodeTree<T>::getData() const {
|
||||
return data;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* NodeTree<T>::getDataRef() {
|
||||
return &data;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void NodeTree<T>::setData(T data) {
|
||||
this->data = data;
|
||||
|
||||
@@ -49,10 +49,9 @@ class Parser {
|
||||
|
||||
std::vector< State* > stateSets;
|
||||
|
||||
//The EOFSymbol, a pointer because of use in table, etc
|
||||
Symbol EOFSymbol;
|
||||
//The nullSymbol, ditto with above. Also used in comparisons
|
||||
Symbol nullSymbol;
|
||||
Symbol invalidSymbol;
|
||||
|
||||
Table table;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user