Pretty naive import implementation. Still not complete.

imports
Justyna Ilczuk 2013-01-07 18:07:25 +01:00
parent 1088069b4e
commit 7ff93163f4
2 changed files with 72 additions and 0 deletions

View File

@ -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();
}

View File

@ -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_ */