From 5a2baa1e94ceabb72907a57a0fdba1a940bdb253 Mon Sep 17 00:00:00 2001 From: jimtahu Date: Sat, 7 Sep 2013 15:21:32 -0500 Subject: [PATCH] IdexedValue Starting work on a value type reps an item indexed out of a list. --- Identifier.h | 4 ++-- IdexedValue.cpp | 29 +++++++++++++++++++++++++++++ IdexedValue.h | 26 ++++++++++++++++++++++++++ LangS.ypp | 3 +++ ParseTree.h | 1 + 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 IdexedValue.cpp create mode 100644 IdexedValue.h diff --git a/Identifier.h b/Identifier.h index 3f6304f..2875304 100644 --- a/Identifier.h +++ b/Identifier.h @@ -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(); }; diff --git a/IdexedValue.cpp b/IdexedValue.cpp new file mode 100644 index 0000000..62cbddb --- /dev/null +++ b/IdexedValue.cpp @@ -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; +} + +} + diff --git a/IdexedValue.h b/IdexedValue.h new file mode 100644 index 0000000..aa593f9 --- /dev/null +++ b/IdexedValue.h @@ -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 diff --git a/LangS.ypp b/LangS.ypp index 975db78..5ba8abe 100644 --- a/LangS.ypp +++ b/LangS.ypp @@ -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; } diff --git a/ParseTree.h b/ParseTree.h index 59154ae..d9aefe3 100644 --- a/ParseTree.h +++ b/ParseTree.h @@ -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"