Skip to content

Commit

Permalink
Merge branch 'classed'
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtahu committed Apr 27, 2013
2 parents 00860cd + d86ed98 commit 0977b3c
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LangS.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
28 changes: 28 additions & 0 deletions ListVariable.cpp
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions ListVariable.h
Original file line number Diff line number Diff line change
@@ -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_ */
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SRC= $(wildcard *.cpp)
OBJ= $(SRC:.cpp=.o) LangS.tab.o LangS.yy.o


all: LangS test

LangS: $(OBJ)
$(CXX) -o $@ $^

Expand Down
29 changes: 29 additions & 0 deletions ScalarVariable.cpp
Original file line number Diff line number Diff line change
@@ -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
}

23 changes: 23 additions & 0 deletions ScalarVariable.h
Original file line number Diff line number Diff line change
@@ -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_ */
25 changes: 25 additions & 0 deletions Variable.cpp
Original file line number Diff line number Diff line change
@@ -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
}

25 changes: 25 additions & 0 deletions Variable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Variable.h
*
* Created on: Apr 25, 2013
* Author: jimtahu
*/

#ifndef VARIABLE_H_
#define VARIABLE_H_

#include <string>

using namespace std;

class Variable {
private:
string Name;
public:
Variable(string name);
Variable(Variable &other);
virtual string GetName();
virtual ~Variable();
};

#endif /* VARIABLE_H_ */

0 comments on commit 0977b3c

Please sign in to comment.