diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..28fcbbc --- /dev/null +++ b/CMakeLists.txt @@ -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}) + diff --git a/README.md b/README.md index 6c21c77..8ba3cba 100644 --- a/README.md +++ b/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. diff --git a/include/NodeTree.h b/include/NodeTree.h new file mode 100644 index 0000000..a0e5fc7 --- /dev/null +++ b/include/NodeTree.h @@ -0,0 +1,40 @@ +#ifndef NODETREE_H +#define NODETREE_H + +#ifndef NULL +#define NULL 0 +#endif NULL + +#include +#include + +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 children; +}; + +#endif //NODETREE_H \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d3856ae --- /dev/null +++ b/main.cpp @@ -0,0 +1,38 @@ +#include "NodeTree.h" +#include +#include +#include + + +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); + +} + \ No newline at end of file diff --git a/src/NodeTree.cpp b/src/NodeTree.cpp new file mode 100644 index 0000000..63c307b --- /dev/null +++ b/src/NodeTree.cpp @@ -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); +} \ No newline at end of file