diff --git a/LangS.ypp b/LangS.ypp index e019009..fe2db59 100644 --- a/LangS.ypp +++ b/LangS.ypp @@ -30,7 +30,7 @@ Program *theProg; %% Prog: Stm ';' Prog { theProg->add((Statement *)$1); } - | Stm ';' { theProg->add((Statement *)$1); } + | Stm ';' { theProg->add((Statement *)$1); } Stm: Exit { $$ = new ExitStatement();} | Scalar '=' Value { $$ = new AssingmentStatement((Identifier*)$1,(Value*)$3); } diff --git a/ListVariable.cpp b/ListVariable.cpp new file mode 100644 index 0000000..4e395cf --- /dev/null +++ b/ListVariable.cpp @@ -0,0 +1,28 @@ +/* + * List.cpp + * + * Created on: Apr 25, 2013 + * Author: jimtahu + */ + +#include "ListVariable.h" + +ListVarable::ListVarable(string name):Variable(name) { + this->head=NULL; +} + +void ListVarable::add(string value){ + ListItem *item = new ListItem(); + item->value=value; + item->next=this->head; + this->head=item; +} + +ListVarable::~ListVarable() { + ListItem *item = this->head; + while(this->head != NULL){ + this->head=item->next; + delete item; + item=this->head; + }//end while list items +} diff --git a/ListVariable.h b/ListVariable.h new file mode 100644 index 0000000..631a72d --- /dev/null +++ b/ListVariable.h @@ -0,0 +1,28 @@ +/* + * List.h + * + * Created on: Apr 25, 2013 + * Author: jimtahu + */ + +#ifndef LIST_H_ +#define LIST_H_ + +#include "Variable.h" + +class ListItem { +public: + string value; + ListItem *next; +public: +}; + +class ListVarable: public Variable { + ListItem *head; +public: + ListVarable(string name); + void add(string value); + virtual ~ListVarable(); +}; + +#endif /* LIST_H_ */ diff --git a/Makefile b/Makefile index dbbb3db..4462e07 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,8 @@ SRC= $(wildcard *.cpp) OBJ= $(SRC:.cpp=.o) LangS.tab.o LangS.yy.o +all: LangS test + LangS: $(OBJ) $(CXX) -o $@ $^ diff --git a/ScalarVariable.cpp b/ScalarVariable.cpp new file mode 100644 index 0000000..0a65c92 --- /dev/null +++ b/ScalarVariable.cpp @@ -0,0 +1,29 @@ +/* + * ScalarVariable.cpp + * + * Created on: Apr 26, 2013 + * Author: jimtahu + */ + +#include "ScalarVariable.h" + +ScalarVariable::ScalarVariable(string name):Variable(name){ + this->Value=""; +} + +ScalarVariable::ScalarVariable(ScalarVariable &other):Variable(other){ + this->Value=other.GetValue(); +} + +string ScalarVariable::GetValue(void){ + return this->Value; +} + +void ScalarVariable::SetValue(string value){ + this->Value=value; +} + +ScalarVariable::~ScalarVariable() { + // TODO Auto-generated destructor stub +} + diff --git a/ScalarVariable.h b/ScalarVariable.h new file mode 100644 index 0000000..0f906fb --- /dev/null +++ b/ScalarVariable.h @@ -0,0 +1,23 @@ +/* + * ScalarVariable.h + * + * Created on: Apr 26, 2013 + * Author: jimtahu + */ + +#ifndef SCALARVARIABLE_H_ +#define SCALARVARIABLE_H_ + +#include "Variable.h" + +class ScalarVariable: public Variable { + string Value; +public: + ScalarVariable(string name); + ScalarVariable(ScalarVariable &other); + string GetValue(); + void SetValue(string value); + virtual ~ScalarVariable(); +}; + +#endif /* SCALARVARIABLE_H_ */ diff --git a/Variable.cpp b/Variable.cpp new file mode 100644 index 0000000..1f6cf8f --- /dev/null +++ b/Variable.cpp @@ -0,0 +1,25 @@ +/* + * Variable.cpp + * + * Created on: Apr 25, 2013 + * Author: jimtahu + */ + +#include "Variable.h" + +Variable::Variable(string name){ + this->Name=name; +} + +Variable::Variable(Variable &other){ + this->Name=other.GetName(); +} + +string Variable::GetName(void){ + return this->Name; +} + +Variable::~Variable(){ + // TODO Auto-generated destructor stub +} + diff --git a/Variable.h b/Variable.h new file mode 100644 index 0000000..37564c6 --- /dev/null +++ b/Variable.h @@ -0,0 +1,25 @@ +/* + * Variable.h + * + * Created on: Apr 25, 2013 + * Author: jimtahu + */ + +#ifndef VARIABLE_H_ +#define VARIABLE_H_ + +#include + +using namespace std; + +class Variable { +private: + string Name; +public: + Variable(string name); + Variable(Variable &other); + virtual string GetName(); + virtual ~Variable(); +}; + +#endif /* VARIABLE_H_ */