Skip to content

Commit

Permalink
IdexedValue
Browse files Browse the repository at this point in the history
Starting work on a value type reps an item indexed out of a list.
  • Loading branch information
jimtahu committed Sep 7, 2013
1 parent 4783509 commit 5a2baa1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Identifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Identifier: public ParseTree::Value {
std::string Name;
public:
Identifier(std::string name);
std::string getName();
std::string getValue();
virtual std::string getName();
virtual std::string getValue();
virtual ~Identifier();
};

Expand Down
29 changes: 29 additions & 0 deletions IdexedValue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Idexed.cpp
*
* Created on: Sep 7, 2013
* Author: jimtahu
*/

#include "IdexedValue.h"

namespace ParseTree {

IdexedValue::IdexedValue(Identifier *name, Value *index)
{
this->name = name;
this->index = index;
}

std::string IdexedValue::getValue()
{
return "indexed thingy";
}

unsigned int IdexedValue::getIndex()
{
return 0;
}

}

26 changes: 26 additions & 0 deletions IdexedValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Idexed.h
*
* Created on: Sep 7, 2013
* Author: jimtahu
*/

#ifndef IDEXED_H_
#define IDEXED_H_

#include "Identifier.h"

namespace ParseTree {

class IdexedValue: public ParseTree::Value {
Identifier *name;
Value *index;
public:
IdexedValue(Identifier *name, Value *index);
virtual std::string getValue();
virtual unsigned int getIndex();
};

}

#endif
3 changes: 3 additions & 0 deletions LangS.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Value: STRING { $$ = $1; }
| Ident { $$ = $1; }
| Items { $$ = $1; }
| Value BinOP Value { $$ = new BinOpValue(((Identifier*)$2)->getName(),(Value*)$1,(Value*)$3); }
| IdexValue { $$ = $1; }

IdexValue: Ident '[' Value ']' { $$ = new IdexedValue((Identifier*)$1,(Value*)$3); }

Items: '[' List ']' { $$ = $2; }

Expand Down
1 change: 1 addition & 0 deletions ParseTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "StringValue.h"
#include "ListValue.h"
#include "BinOpValue.h"
#include "IdexedValue.h"
#include "Statement.h"
#include "AssingmentStatement.h"
#include "ExitStatement.h"
Expand Down

0 comments on commit 5a2baa1

Please sign in to comment.