summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-07 18:07:25 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-07 18:07:25 +0100
commit7ff93163f4dbde6c2c7c54e30bbc70b5514a66f7 (patch)
tree8a25ebc39ee0c09445c3a838458e3d2db7b6df94
parent1088069b4ef3ed2a773629b20a633eddbfe0aa67 (diff)
downloadsencha-lang-7ff93163f4dbde6c2c7c54e30bbc70b5514a66f7.tar.gz
sencha-lang-7ff93163f4dbde6c2c7c54e30bbc70b5514a66f7.tar.bz2
sencha-lang-7ff93163f4dbde6c2c7c54e30bbc70b5514a66f7.zip
Pretty naive import implementation. Still not complete.
-rw-r--r--Sencha-lang/AST/ImportStatement.cpp42
-rw-r--r--Sencha-lang/AST/ImportStatement.h30
2 files changed, 72 insertions, 0 deletions
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<Token> 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 <fstream>
+#include <iostream>
+
+#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_ */