# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/loader/Interpreter.cpp \
../src/loader/ParsedSource.cpp \
../src/loader/Parser.cpp \
../src/loader/Tokenizer.cpp
OBJS += \
+./src/loader/Interpreter.o \
./src/loader/ParsedSource.o \
./src/loader/Parser.o \
./src/loader/Tokenizer.o
CPP_DEPS += \
+./src/loader/Interpreter.d \
./src/loader/ParsedSource.d \
./src/loader/Parser.d \
./src/loader/Tokenizer.d
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/loader/Interpreter.cpp \
../src/loader/ParsedSource.cpp \
../src/loader/Parser.cpp \
../src/loader/Tokenizer.cpp
OBJS += \
+./src/loader/Interpreter.o \
./src/loader/ParsedSource.o \
./src/loader/Parser.o \
./src/loader/Tokenizer.o
CPP_DEPS += \
+./src/loader/Interpreter.d \
./src/loader/ParsedSource.d \
./src/loader/Parser.d \
./src/loader/Tokenizer.d
--- /dev/null
+/*
+ * Interpreter.cpp
+ *
+ * Created on: Aug 26, 2012
+ * Author: holy
+ */
+
+#include "Interpreter.h"
+
+#include "ParsedSource.h"
+#include "../battle/Monster.h"
+
+using battle::Monster;
+using std::map;
+using std::set;
+using std::string;
+
+namespace loader {
+
+void Interpreter::ReadSource() {
+ for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
+ const Definition &dfn(source.GetDefinition(*i));
+ if (dfn.HasLiteralValue()) {
+ ReadLiteral(dfn);
+ } else {
+ ReadObject(dfn);
+ }
+ }
+}
+
+void Interpreter::ReadLiteral(const Definition &dfn) {
+ switch (dfn.GetLiteral()->GetType()) {
+ case Literal::ARRAY_VALUES:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::ARRAY_PROPS:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::BOOLEAN:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::COLOR:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::NUMBER:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::STRING:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::VECTOR:
+ throw Error("unhandled literal: array of values");
+ break;
+ case Literal::OBJECT:
+ throw Error("unhandled literal: array of values");
+ break;
+ }
+}
+
+void Interpreter::ReadObject(const Definition &dfn) {
+ if (dfn.TypeName() == "Monster") {
+ monsters.resize(monsters.size() + 1);
+ ReadMonster(monsters.back(), *dfn.GetProperties());
+ } else {
+ throw Error("unhandled object: " + dfn.TypeName());
+ }
+}
+
+
+void Interpreter::ReadMonster(Monster &m, const PropertyList &props) {
+ for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
+ if (i->first == "name") {
+ if (i->second->IsLiteral()) {
+ m.SetName(i->second->GetLiteral().GetString().c_str());
+ } else {
+ throw Error("identifier resolution not implemented");
+ }
+ } else {
+ throw Error("unknown monster property: " + i->first);
+ }
+ }
+}
+
+}
--- /dev/null
+/*
+ * Interpreter.h
+ *
+ * Created on: Aug 26, 2012
+ * Author: holy
+ */
+
+#ifndef LOADER_INTERPRETER_H_
+#define LOADER_INTERPRETER_H_
+
+#include <map>
+#include <stdexcept>
+#include <string>
+#include <vector>
+
+namespace battle {
+ class Monster;
+}
+
+namespace loader {
+
+class Definition;
+class ParsedSource;
+class PropertyList;
+
+class Interpreter {
+
+public:
+ class Error: public std::runtime_error {
+ public:
+ Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
+ };
+
+public:
+ Interpreter(const ParsedSource &source) : source(source) { }
+ ~Interpreter() { }
+private:
+ Interpreter(const Interpreter &);
+ Interpreter &operator =(const Interpreter &);
+
+public:
+ void ReadSource();
+
+private:
+ void ReadLiteral(const Definition &);
+ void ReadObject(const Definition &);
+
+ void ReadMonster(battle::Monster &, const PropertyList &);
+
+private:
+ const ParsedSource &source;
+ std::vector<battle::Monster> monsters;
+
+};
+
+}
+
+#endif /* LOADER_INTERPRETER_H_ */
#include "graphics/Menu.h"
#include "graphics/SimpleAnimation.h"
#include "graphics/Sprite.h"
+#include "loader/Interpreter.h"
#include "loader/ParsedSource.h"
#include "loader/Parser.h"
#include "sdl/InitImage.h"
using graphics::Menu;
using graphics::SimpleAnimation;
using graphics::Sprite;
+using loader::Interpreter;
using loader::ParsedSource;
using loader::Parser;
using sdl::InitImage;
ParsedSource source;
Parser parser("test-data/test.l2s", source);
parser.Parse();
-
cout << source;
+ Interpreter intp(source);
+ intp.ReadSource();
return 0;