diff --git a/jlc/ASTNode.cc b/jlc/ASTNode.cc new file mode 100644 index 0000000..df7ea5c --- /dev/null +++ b/jlc/ASTNode.cc @@ -0,0 +1,15 @@ + +#include "ASTNode.h" + +ASTNode::~ASTNode() +{ + /* clean up any children nodes */ + int sz = myChildren.size(); + for (int i = 0; i < sz; i++) + delete myChildren[i]; +} + +void ASTNode::addChild(ASTNode * node) +{ + myChildren.push_back(node); +} diff --git a/jlc/ASTNode.h b/jlc/ASTNode.h new file mode 100644 index 0000000..dbc2aee --- /dev/null +++ b/jlc/ASTNode.h @@ -0,0 +1,13 @@ + +#include + +class ASTNode +{ +public: + virtual ~ASTNode(); + void addChild(ASTNode * node); + std::vector & getChildren() { return myChildren; } + +private: + std::vector myChildren; +}; diff --git a/jlc/Makefile b/jlc/Makefile index c580011..d824754 100644 --- a/jlc/Makefile +++ b/jlc/Makefile @@ -7,6 +7,7 @@ LDFLAGS := -lfl COBJS := lex.yy.o CXXOBJS := $(TARGET).tab.o +CXXOBJS += ASTNode.o all: $(TARGET) diff --git a/jlc/jlc.yy b/jlc/jlc.yy index d01d5be..be36d16 100644 --- a/jlc/jlc.yy +++ b/jlc/jlc.yy @@ -152,7 +152,7 @@ assignment: ID ASSIGN number SEMICOLON ; int main(int argc, char * argv[]) { - if (argc > 0) + if (argc > 1) { yyin = fopen(argv[1], "r"); if (yyin == NULL)