diff --git a/AssingmentStatement.cpp b/AssingmentStatement.cpp index 363eccc..b596d4d 100644 --- a/AssingmentStatement.cpp +++ b/AssingmentStatement.cpp @@ -6,6 +6,7 @@ */ #include "AssingmentStatement.h" +#include "Variable.h" namespace ParseTree { @@ -14,6 +15,10 @@ AssingmentStatement::AssingmentStatement(Identifier *id, Value *value) { this->value=value; } +void AssingmentStatement::Execute(){ + setScalar(this->id->getName(),this->value->getValue()); +} + AssingmentStatement::~AssingmentStatement() { // TODO Auto-generated destructor stub } diff --git a/AssingmentStatement.h b/AssingmentStatement.h index 84229e8..3523810 100644 --- a/AssingmentStatement.h +++ b/AssingmentStatement.h @@ -19,6 +19,7 @@ class AssingmentStatement: public ParseTree::Statement { Value *value; public: AssingmentStatement(Identifier *id, Value *value); + void Execute(); virtual ~AssingmentStatement(); }; diff --git a/Identifier.cpp b/Identifier.cpp index 3c3a8bb..c5aa3a5 100644 --- a/Identifier.cpp +++ b/Identifier.cpp @@ -6,6 +6,7 @@ */ #include "Identifier.h" +#include "Variable.h" namespace ParseTree { @@ -19,6 +20,10 @@ string Identifier::getName(){ return this->Name; } +string Identifier::getValue(){ + return getScalar(this->Name); +} + Identifier::~Identifier() { // TODO Auto-generated destructor stub } diff --git a/Identifier.h b/Identifier.h index aa13094..3f6304f 100644 --- a/Identifier.h +++ b/Identifier.h @@ -18,7 +18,7 @@ class Identifier: public ParseTree::Value { public: Identifier(std::string name); std::string getName(); - void setValue(std::string value); + std::string getValue(); virtual ~Identifier(); }; diff --git a/Program.cpp b/Program.cpp index f52026c..876a831 100644 --- a/Program.cpp +++ b/Program.cpp @@ -14,7 +14,7 @@ Program::Program() { } void Program::add(Statement *stmt){ - this->code.push_back(stmt); + code.insert(code.begin(),stmt); } void Program::run(){ diff --git a/Variable.cpp b/Variable.cpp index 1f6cf8f..2eda14a 100644 --- a/Variable.cpp +++ b/Variable.cpp @@ -5,7 +5,38 @@ * Author: jimtahu */ +#include + #include "Variable.h" +#include "ScalarVariable.h" + +using namespace std; + +map varTable; + +/** +* Places a varable into the table. +* @param name The lable for the varable. +* @param value The value the varable now holds. +* @return value, for convienace. +*/ +string setScalar(string name, string value){ + if(varTable.count(name)==0)varTable[name]=new ScalarVariable(name); + varTable[name]->SetValue(value); + return value; +}//end setValue + +/** +* Fetches the value for a varable. +* @param name The lable of the varable to fetch. +* @return the value. +* Fetching a variable which has not been stored is undefined. +*/ +string getScalar(string name){ + if(varTable.count(name)) + return varTable[name]->GetValue(); + else return "EMPTY"; +}//end getValue Variable::Variable(string name){ this->Name=name; diff --git a/Variable.h b/Variable.h index 37564c6..66a31bf 100644 --- a/Variable.h +++ b/Variable.h @@ -12,6 +12,9 @@ using namespace std; +string setScalar(string name, string value); +string getScalar(string name); + class Variable { private: string Name;