First work on Kraken! Basic node tree system re-written from WTS-Language, can output .gv files of the node tree.
This commit is contained in:
12
CMakeLists.txt
Normal file
12
CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
|
||||
project(Kraken)
|
||||
|
||||
set( MY_INCLUDES ${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
set( MY_SOURCES main.cpp src/NodeTree.cpp )
|
||||
|
||||
include_directories( ${MY_INCLUDES} )
|
||||
|
||||
add_executable(kraken ${MY_SOURCES})
|
||||
|
||||
13
README.md
13
README.md
@@ -1,4 +1,15 @@
|
||||
kraken
|
||||
Kraken
|
||||
======
|
||||
|
||||
The Kraken Programming Language
|
||||
|
||||
The Kraken Programming Language is in its infancy.
|
||||
|
||||
It has the following design goals:
|
||||
-Compiled
|
||||
-Clean
|
||||
-Fast (both running and writing)
|
||||
-Good for Systems (including Operating Systems) programming
|
||||
-Minimal "magic" code. (no runtime, other libraries automatically included)
|
||||
|
||||
It is inspired by C/C++, Python, and Go.
|
||||
|
||||
40
include/NodeTree.h
Normal file
40
include/NodeTree.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef NODETREE_H
|
||||
#define NODETREE_H
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif NULL
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class NodeTree {
|
||||
public:
|
||||
NodeTree();
|
||||
NodeTree(std::string name);
|
||||
~NodeTree();
|
||||
|
||||
void setParent(NodeTree* parent);
|
||||
NodeTree* getParent();
|
||||
|
||||
void addChild(NodeTree* child);
|
||||
int findChild(NodeTree* child);
|
||||
void removeChild(NodeTree* child);
|
||||
void removeChild(int index);
|
||||
|
||||
NodeTree* get(int index);
|
||||
std::string getName();
|
||||
|
||||
void setName(std::string);
|
||||
|
||||
int size();
|
||||
std::string DOTGraphString();
|
||||
|
||||
private:
|
||||
std::string DOTGraphStringHelper();
|
||||
std::string name;
|
||||
NodeTree* parent;
|
||||
std::vector<NodeTree*> children;
|
||||
};
|
||||
|
||||
#endif //NODETREE_H
|
||||
38
main.cpp
Normal file
38
main.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "NodeTree.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
std::ifstream inFile;
|
||||
std::ofstream outFile;
|
||||
|
||||
inFile.open(argv[1]);
|
||||
if (!inFile.is_open()) {
|
||||
std::cout << "Problem opening input file " << argv[1] << "\n";
|
||||
return(1);
|
||||
}
|
||||
|
||||
outFile.open(argv[2]);
|
||||
if (!outFile.is_open()) {
|
||||
std::cout << "Probelm opening output file " << argv[2] << "\n";
|
||||
return(1);
|
||||
}
|
||||
|
||||
NodeTree root;
|
||||
root.setName("Root");
|
||||
root.addChild(new NodeTree("SomeChild"));
|
||||
root.addChild(new NodeTree("SomeOtherChild"));
|
||||
root.get(0)->addChild(new NodeTree("Grandchildren"));
|
||||
|
||||
outFile << root.DOTGraphString() << std::endl;
|
||||
|
||||
inFile.close();
|
||||
outFile.close();
|
||||
|
||||
return(0);
|
||||
|
||||
}
|
||||
|
||||
84
src/NodeTree.cpp
Normal file
84
src/NodeTree.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "NodeTree.h"
|
||||
|
||||
NodeTree::NodeTree() {
|
||||
parent = NULL;
|
||||
name = "UnnamedNode";
|
||||
}
|
||||
|
||||
NodeTree::NodeTree(std::string name) {
|
||||
parent = NULL;
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
NodeTree::~NodeTree() {
|
||||
children.clear();
|
||||
}
|
||||
|
||||
void NodeTree::setParent(NodeTree* parent) {
|
||||
if (this->parent != NULL) {
|
||||
this->parent->removeChild(this);
|
||||
}
|
||||
this->parent = parent;
|
||||
}
|
||||
|
||||
NodeTree* NodeTree::getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
void NodeTree::addChild(NodeTree* child) {
|
||||
if (findChild(child) == -1)
|
||||
children.push_back(child);
|
||||
}
|
||||
|
||||
int NodeTree::findChild(NodeTree* child) {
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
if (children[i] == child) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void NodeTree::removeChild(int index) {
|
||||
children[index] = NULL;
|
||||
children.erase(children.begin()+index);
|
||||
}
|
||||
|
||||
void NodeTree::removeChild(NodeTree* child) {
|
||||
int index = findChild(child);
|
||||
if (index != 0) {
|
||||
removeChild(index);
|
||||
}
|
||||
}
|
||||
|
||||
int NodeTree::size() {
|
||||
int count = 0;
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
count += children[i]->size();
|
||||
}
|
||||
return 1+count;
|
||||
}
|
||||
|
||||
NodeTree* NodeTree::get(int index) {
|
||||
return children[index];
|
||||
}
|
||||
|
||||
std::string NodeTree::getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
void NodeTree::setName(std::string name) {
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
std::string NodeTree::DOTGraphString() {
|
||||
return( "digraph Kraken { \n" + DOTGraphStringHelper() + "}");
|
||||
}
|
||||
|
||||
std::string NodeTree::DOTGraphStringHelper() {
|
||||
std::string ourDOTRelation = "";
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
ourDOTRelation += name + " -> " + children[i]->name + ";\n" + children[i]->DOTGraphStringHelper();
|
||||
}
|
||||
return(ourDOTRelation);
|
||||
}
|
||||
Reference in New Issue
Block a user