Skip to content

Commit

Permalink
Merge branch 'classed'
Browse files Browse the repository at this point in the history
Conflicts:
	PrintStatement.cpp
  • Loading branch information
jimtahu committed Apr 27, 2013
2 parents 0977b3c + 83aec26 commit e9ec23a
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 3 deletions.
5 changes: 5 additions & 0 deletions AssingmentStatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "AssingmentStatement.h"
#include "Variable.h"

namespace ParseTree {

Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions AssingmentStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AssingmentStatement: public ParseTree::Statement {
Value *value;
public:
AssingmentStatement(Identifier *id, Value *value);
void Execute();
virtual ~AssingmentStatement();
};

Expand Down
5 changes: 5 additions & 0 deletions Identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "Identifier.h"
#include "Variable.h"

namespace ParseTree {

Expand All @@ -19,6 +20,10 @@ string Identifier::getName(){
return this->Name;
}

string Identifier::getValue(){
return getScalar(this->Name);
}

Identifier::~Identifier() {
// TODO Auto-generated destructor stub
}
Expand Down
2 changes: 1 addition & 1 deletion Identifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
4 changes: 3 additions & 1 deletion PrintStatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Author: jimtahu
*/

#include <iostream>

#include "PrintStatement.h"
#include <iostream>

Expand All @@ -17,7 +19,7 @@ PrintStatement::PrintStatement(Value *output) {
}

void PrintStatement::Execute(){
cout << this->value->getValue() << endl;
cout<<this->value->getValue()<<endl;
}

PrintStatement::~PrintStatement() {
Expand Down
2 changes: 1 addition & 1 deletion Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Program::Program() {
}

void Program::add(Statement *stmt){
this->code.push_back(stmt);
code.insert(code.begin(),stmt);
}

void Program::run(){
Expand Down
31 changes: 31 additions & 0 deletions Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,38 @@
* Author: jimtahu
*/

#include <map>

#include "Variable.h"
#include "ScalarVariable.h"

using namespace std;

map<string, ScalarVariable*> 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;
Expand Down
3 changes: 3 additions & 0 deletions Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

using namespace std;

string setScalar(string name, string value);
string getScalar(string name);

class Variable {
private:
string Name;
Expand Down

0 comments on commit e9ec23a

Please sign in to comment.