From 7ff93163f4dbde6c2c7c54e30bbc70b5514a66f7 Mon Sep 17 00:00:00 2001 From: Justyna Ilczuk Date: Mon, 7 Jan 2013 18:07:25 +0100 Subject: [PATCH] Pretty naive import implementation. Still not complete. --- Sencha-lang/AST/ImportStatement.cpp | 42 +++++++++++++++++++++++++++++ Sencha-lang/AST/ImportStatement.h | 30 +++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Sencha-lang/AST/ImportStatement.cpp create mode 100644 Sencha-lang/AST/ImportStatement.h diff --git a/Sencha-lang/AST/ImportStatement.cpp b/Sencha-lang/AST/ImportStatement.cpp new file mode 100644 index 0000000..9f05da0 --- /dev/null +++ b/Sencha-lang/AST/ImportStatement.cpp @@ -0,0 +1,42 @@ +/* + * ImportStatement.cpp + * + * Created on: Jan 7, 2013 + * Author: att + */ + +#include "ImportStatement.h" + +ImportStatement::ImportStatement(std::string name_of_module, ContextManager * context_manager) : +name_of_module(name_of_module), context_manager(context_manager){ + //Hrum hrum magic + + std::ifstream module_file(name_of_module); + std::string module_source_text = ""; + std::string line; + Lexer lexer; + vector tokens; + Parser parser(context_manager); + if (module_file.is_open()) + { + while ( module_file.good() ) + { + getline (module_file, line); + module_source_text += line; + tokens = lexer.parse_line(line); + parser.add_tokens(tokens); + } + module_file.close(); + } + import_body = parser.interpret(); + children.push_back(import_body); +} + +ImportStatement::~ImportStatement() { + // TODO Auto-generated destructor stub +} + +SenchaObject ImportStatement::execute() +{ + return import_body->execute(); +} diff --git a/Sencha-lang/AST/ImportStatement.h b/Sencha-lang/AST/ImportStatement.h new file mode 100644 index 0000000..8472d1a --- /dev/null +++ b/Sencha-lang/AST/ImportStatement.h @@ -0,0 +1,30 @@ +/* + * ImportStatement.h + * + * Created on: Jan 7, 2013 + * Author: att + */ + +#ifndef IMPORTSTATEMENT_H_ +#define IMPORTSTATEMENT_H_ + +#include +#include + +#include "ASTStatement.h" +#include "../Parser.h" +#include "../Lexer.h" +#include "../ContextManager.h" + +class ImportStatement: public ASTStatement { +public: + std::string name_of_module; + ContextManager * context_manager; + + ImportStatement(std::string name_of_module, ContextManager * context_manager); + ProgramNode * import_body; + SenchaObject execute(); + virtual ~ImportStatement(); +}; + +#endif /* IMPORTSTATEMENT_H_ */