diff --git a/eci/Class.cpp b/eci/Class.cpp new file mode 100644 index 0000000..fd55f83 --- /dev/null +++ b/eci/Class.cpp @@ -0,0 +1,11 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include + diff --git a/eci/Class.h b/eci/Class.h new file mode 100644 index 0000000..c566816 --- /dev/null +++ b/eci/Class.h @@ -0,0 +1,22 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_CLASS_H__ +#define __ECI_CLASS_H__ + +#include + +namespace eci { + class Class { + public: + Class() {}; + ~Class() {}; + }; +} + +#endif diff --git a/eci/Enum.cpp b/eci/Enum.cpp new file mode 100644 index 0000000..dd209a7 --- /dev/null +++ b/eci/Enum.cpp @@ -0,0 +1,62 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include + +void eci::Enum::addValue(const std::string& _name) { + if (m_values.size() == 0) { + m_values.push_back(std::make_pair(_name, 0)); + return; + } + int32_t lastValue = 0; + for (size_t iii=0; iii + +namespace eci { + class Enum { + public: + Enum() {}; + ~Enum() {}; + protected: + std::vector> m_values; + public: + void addValue(const std::string& _name); + void addValue(const std::string& _name, int32_t _value); + int32_t getValue(const std::string& _name) const; + const std::string& getName(int32_t _value) const; + }; +} + +#endif diff --git a/eci/File.cpp b/eci/File.cpp new file mode 100644 index 0000000..96a4b29 --- /dev/null +++ b/eci/File.cpp @@ -0,0 +1,39 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include +#include +#include + + +static std::string getValue(const std::string& _file, const std::shared_ptr& _it) { + return std::string(_file, _it->getStartPos(), _it->getStopPos()-_it->getStartPos()); +} + +eci::File::File(const std::string& _filename) { + m_fileName = _filename; + m_fileData = etk::FSNodeReadAllData(_filename); + eci::ParserCpp tmpParser; + tmpParser.parse(m_fileData); + std::string value; + for (auto &it : tmpParser.m_result.m_list) { + switch (it->getTockenId()) { + case tokenCppVisibility: + ECI_INFO("get visibility : " << getValue(m_fileData, it) << "'" ); + break; + case tokenCppType: + ECI_INFO("get type : " << getValue(m_fileData, it) << "'" ); + break; + case tokenCppString: + ECI_INFO("get string : " << getValue(m_fileData, it) << "'" ); + break; + } + } +} + diff --git a/eci/File.h b/eci/File.h new file mode 100644 index 0000000..77f3967 --- /dev/null +++ b/eci/File.h @@ -0,0 +1,29 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_FILE_H__ +#define __ECI_FILE_H__ + +#include +#include +#include +#include +#include + +namespace eci { + class File { + public: + File(const std::string& _filename); + ~File() {}; + protected: + std::string m_fileName; //!< Name of the file. + std::string m_fileData; //!< Data of the file. + }; +} + +#endif diff --git a/eci/Function.cpp b/eci/Function.cpp new file mode 100644 index 0000000..cee219e --- /dev/null +++ b/eci/Function.cpp @@ -0,0 +1,28 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include + + +eci::Function::Function() : + m_const(false), + m_static(false), + m_visibility(eci::visibilityPublic){ + +} + +eci::Function::~Function() { + +} + +std::vector> eci::Function::call(const std::vector>& _input) { + return std::vector>(); +} + + diff --git a/eci/Function.h b/eci/Function.h new file mode 100644 index 0000000..06f2269 --- /dev/null +++ b/eci/Function.h @@ -0,0 +1,35 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_FUNCTION_H__ +#define __ECI_FUNCTION_H__ + +#include +#include +#include +#include +#include + +namespace eci { + class Function { + public: + Function(); + ~Function(); + protected: + std::string m_name; //!< Function Name. + bool m_const; //!< The function is const. + bool m_static; //!< function is static. + enum eci::visibility m_visibility; //!< Visibility of the function + std::vector m_return; //!< return value. + std::vector m_arguments; //!< return value. + + std::vector> call(const std::vector>& _input); + }; +} + +#endif diff --git a/eci/Interpreter.cpp b/eci/Interpreter.cpp new file mode 100644 index 0000000..095771b --- /dev/null +++ b/eci/Interpreter.cpp @@ -0,0 +1,29 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include + +eci::Interpreter::Interpreter() { + +} + +eci::Interpreter::~Interpreter() { + +} + +void eci::Interpreter::addFile(const std::string& _filename) { + // TODO : Check if file is not previously loaded ... + m_files.push_back(eci::File(_filename)); +} + +void eci::Interpreter::main() { + ECI_TODO("create the main ... "); +} + + diff --git a/eci/Interpreter.h b/eci/Interpreter.h new file mode 100644 index 0000000..8004be4 --- /dev/null +++ b/eci/Interpreter.h @@ -0,0 +1,30 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_INTERPRETER_H__ +#define __ECI_INTERPRETER_H__ + +#include +#include +#include + +namespace eci { + class Interpreter { + public: + Interpreter(); + ~Interpreter(); + protected: + std::vector m_libraries; //!< list of all loaded libraries. + std::vector m_files; //!< List of all files in the current program. + public: + void addFile(const std::string& _filename); + void main(); + }; +} + +#endif diff --git a/eci/Lexer.cpp b/eci/Lexer.cpp index 3bd7bce..c827175 100644 --- a/eci/Lexer.cpp +++ b/eci/Lexer.cpp @@ -18,38 +18,38 @@ eci::Lexer::~Lexer() { } void eci::Lexer::append(int32_t _tokenId, const std::string& _regularExpression) { - ECI_INFO("CPP lexer add : '" << _regularExpression << "'"); + ECI_INFO("CPP lexer add : [" << _tokenId << "] '" << _regularExpression << "'"); try { - m_searchList.insert(std::make_pair(_tokenId, std::make_shared(_tokenId, _regularExpression))); + m_searchList.push_back(std::make_shared(_tokenId, _regularExpression)); } catch (std::exception e){ ECI_ERROR(" create reg exp : '" << _regularExpression << "' : what:" << e.what()); } } -void eci::Lexer::appendSection(int32_t _tokenId, const std::string& _regularExpressionStart, const std::string& _regularExpressionStop) { - ECI_INFO("CPP lexer add section : '" << _regularExpressionStart << "' .. '" << _regularExpressionStop << "'"); +void eci::Lexer::appendSection(int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop) { + ECI_INFO("CPP lexer add section [" << _tokenId << "] : '" << _tockenStart << "' .. '" << _tockenStop << "'"); try { - m_searchList.insert(std::make_pair(_tokenId, std::make_shared(_tokenId, _regularExpressionStart, _regularExpressionStop))); + m_searchList.push_back(std::make_shared(_tokenId, _tockenStart, _tockenStop)); } catch (std::exception e){ - ECI_ERROR(" create reg exp : '" << _regularExpressionStart << "' .. '" << _regularExpressionStop << "' : what:" << e.what()); + ECI_ERROR(" create reg exp : '" << _tockenStart << "' .. '" << _tockenStop << "' : what:" << e.what()); } } void eci::Lexer::appendSub(int32_t _tokenIdParrent, int32_t _tokenId, const std::string& _regularExpression) { - ECI_INFO("CPP lexer add sub : [" << _tokenIdParrent << "] '" << _regularExpression << "'"); + ECI_INFO("CPP lexer add sub : [" << _tokenId << "] [" << _tokenIdParrent << "] '" << _regularExpression << "'"); try { - m_searchList.insert(std::make_pair(_tokenId, std::make_shared(_tokenId, _tokenIdParrent, _regularExpression))); + m_searchList.push_back(std::make_shared(_tokenId, _tokenIdParrent, _regularExpression)); } catch (std::exception e){ ECI_ERROR(" create reg exp : '" << _regularExpression << "' : what:" << e.what()); } } -void eci::Lexer::appendSubSection(int32_t _tokenIdParrent, int32_t _tokenId, const std::string& _regularExpressionStart, const std::string& _regularExpressionStop) { - ECI_INFO("CPP lexer add section sub : [" << _tokenIdParrent << "] '" << _regularExpressionStart << "' .. '" << _regularExpressionStop << "'"); +void eci::Lexer::appendSubSection(int32_t _tokenIdParrent, int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop) { + ECI_INFO("CPP lexer add section sub : [" << _tokenId << "] [" << _tokenIdParrent << "] '" << _tockenStart << "' .. '" << _tockenStop << "'"); try { - m_searchList.insert(std::make_pair(_tokenId, std::make_shared(_tokenId, _tokenIdParrent, _regularExpressionStart, _regularExpressionStop))); + m_searchList.push_back(std::make_shared(_tokenId, _tokenIdParrent, _tockenStart, _tockenStop)); } catch (std::exception e){ - ECI_ERROR(" create reg exp : '" << _regularExpressionStart << "' .. '" << _regularExpressionStop << "' : what:" << e.what()); + ECI_ERROR(" create reg exp : '" << _tockenStart << "' .. '" << _tockenStop << "' : what:" << e.what()); } } @@ -59,80 +59,92 @@ eci::LexerResult eci::Lexer::interprete(const std::string& _data) { ECI_INFO("Parse : \n" << _data); for (auto &it : m_searchList) { //ECI_INFO("Parse RegEx : " << it.first << " : " << it.second.getRegExDecorated()); - if (it.second == nullptr) { + if (it == nullptr) { continue; } - if (it.second->isSubParse() == true) { + if (it->isSubParse() == true) { continue; } - if (result.m_list.size() == 0) { - result.m_list = it.second->parse(_data, 0, _data.size()); - } else { - int32_t start = 0; - auto itList(result.m_list.begin()); - while (itList != result.m_list.end()) { - if (*itList == nullptr) { - ECI_TODO("remove null shared_ptr"); - ++itList; - continue; - } - if ((*itList)->getStartPos() == start) { - // nothing to do .. + if (it->isSection() == false) { + if (result.m_list.size() == 0) { + result.m_list = it->parse(_data, 0, _data.size()); + } else { + int32_t start = 0; + auto itList(result.m_list.begin()); + while (itList != result.m_list.end()) { + if (*itList == nullptr) { + ECI_TODO("remove null shared_ptr"); + ++itList; + continue; + } + if ((*itList)->getStartPos() == start) { + // nothing to do .. + start = (*itList)->getStopPos(); + ++itList; + continue; + } + std::vector> res = it->parse(_data, start, (*itList)->getStartPos()); + // append it in the buffer: + if (res.size() > 0) { + int32_t currentPos = std::distance(result.m_list.begin(), itList) + res.size() ; + result.m_list.insert(itList, res.begin(), res.end()); + itList = result.m_list.begin() + currentPos; + } start = (*itList)->getStopPos(); ++itList; - continue; } - std::vector> res = it.second->parse(_data, start, (*itList)->getStartPos()); - // append it in the buffer: - if (res.size() > 0) { - int32_t currentPos = std::distance(result.m_list.begin(), itList) + res.size() ; - result.m_list.insert(itList, res.begin(), res.end()); - itList = result.m_list.begin() + currentPos; - } - start = (*itList)->getStopPos(); - ++itList; - } - // Do the last element : - if (start < _data.size()) { - std::vector> res = it.second->parse(_data, start, _data.size()); - for (auto &itRes : res) { - result.m_list.push_back(itRes); + // Do the last element : + if (start < _data.size()) { + std::vector> res = it->parse(_data, start, _data.size()); + for (auto &itRes : res) { + result.m_list.push_back(itRes); + } } } + } else { + if (result.m_list.size() == 0) { + continue; + } + it->parseSection(result.m_list); } } return result; } +static std::regex_constants::match_flag_type createFlags(const std::string& _data, int32_t _start, int32_t _stop) { + std::regex_constants::match_flag_type flags = std::regex_constants::match_any; + //ECI_DEBUG("find data at : start=" << _start << " stop=" << _stop << " regex='" << m_regexValue << "'"); + if ((int64_t)_stop <= (int64_t)_data.size()) { + char val = _data[_stop]; + if ( val != '\n' + && val != '\r') { + //after last char ==> not end of line ($ would not work)) + flags |= std::regex_constants::match_not_eol; + } + if (!( ('a' <= val && val <= 'z') + || ('A' <= val && val <= 'Z') + || ('0' <= val && val <= '9') + || val == '_')) { + flags |= std::regex_constants::match_not_eow; + } + } + if (_start>0) { + flags |= std::regex_constants::match_prev_avail; + } + return flags; +} + std::vector> eci::Lexer::TypeBase::parse(const std::string& _data, int32_t _start, int32_t _stop) { std::vector> result; - ECI_DEBUG("parse : " << getValue()); + ECI_VERBOSE("parse : " << getValue()); while (true) { std::smatch resultMatch; - std::regex_constants::match_flag_type flags = std::regex_constants::match_any; - //APPL_DEBUG("find data at : start=" << _start << " stop=" << _stop << " regex='" << m_regexValue << "'"); - if ((int64_t)_stop <= (int64_t)_data.size()) { - char val = _data[_stop]; - if ( val != '\n' - && val != '\r') { - //after last char ==> not end of line ($ would not work)) - flags |= std::regex_constants::match_not_eol; - } - if (!( ('a' <= val && val <= 'z') - || ('A' <= val && val <= 'Z') - || ('0' <= val && val <= '9') - || val == '_')) { - flags |= std::regex_constants::match_not_eow; - } - } - if (_start>0) { - flags |= std::regex_constants::match_prev_avail; - } + std::regex_constants::match_flag_type flags = createFlags(_data, _start, _stop); std::regex_search(_data.begin()+_start, _data.begin()+_stop, resultMatch, regex, flags); if (resultMatch.size() > 0) { int32_t start = std::distance(_data.begin(), resultMatch[0].first); int32_t stop = std::distance(_data.begin(), resultMatch[0].second); - ECI_DEBUG(" find data at : start=" << start << " stop=" << stop << " data='" <(m_tockenId, start, stop)); } else { @@ -142,10 +154,52 @@ std::vector> eci::Lexer::TypeBase::parse(const s return result; } -std::vector> eci::Lexer::TypeSection::parse(const std::string& _data, int32_t _start, int32_t _stop) { - std::vector> result; - ECI_TODO("later 1"); - return result; +void eci::Lexer::TypeSection::parseSectionCurrent(std::vector>& _data) { + std::vector posList; + for (size_t iii=0; iii<_data.size(); ++iii) { + if (_data[iii] == nullptr) { + ECI_TODO("remove null shared_ptr"); + continue; + } + if (_data[iii]->getTockenId() == tockenStart) { + ECI_VERBOSE("Detect start TOCKEN " << iii); + posList.push_back(iii); + } + if (_data[iii]->getTockenId() == tockenStop) { + if (posList.size() == 0) { + ECI_ERROR("Detect end of tocken without start"); + continue; + } + size_t startId = posList.back(); + ECI_VERBOSE("Detect stop TOCKEN " << startId << " => " << iii << " list size=" << posList.size()); + posList.pop_back(); + // agragate the subtoken : + int32_t startPos = _data[startId]->getStartPos(); + int32_t stopPos = _data[iii]->getStopPos(); + std::shared_ptr newContainer = std::make_shared(m_tockenId, startPos, stopPos); + ECI_VERBOSE(" Agregate: " << startId << " -> " << iii); + newContainer->m_list.insert(newContainer->m_list.begin(), _data.begin()+startId, _data.begin()+iii+1); + ECI_VERBOSE(" list size=" << newContainer->m_list.size() << " old=" << _data.size()); + _data.erase(_data.begin()+startId, _data.begin()+iii+1); + ECI_VERBOSE(" list size=" << newContainer->m_list.size() << " old=" << _data.size()); + _data.insert(_data.begin()+startId, newContainer); + ECI_VERBOSE(" list size=" << newContainer->m_list.size() << " old=" << _data.size()); + iii = startId-1; + } + } +} +void eci::Lexer::TypeSection::parseSection(std::vector>& _data) { + ECI_VERBOSE("parse section : " << getValue()); + for (auto &it : _data) { + if (it == nullptr) { + continue; + } + if (it->isNodeContainer() == true) { + std::shared_ptr sec = std::dynamic_pointer_cast(it); + parseSection(sec->m_list); + } + } + parseSectionCurrent(_data); } std::vector> eci::Lexer::TypeSubBase::parse(const std::string& _data, int32_t _start, int32_t _stop) { diff --git a/eci/Lexer.h b/eci/Lexer.h index 3ea0bb9..0013df8 100644 --- a/eci/Lexer.h +++ b/eci/Lexer.h @@ -27,14 +27,20 @@ namespace eci { } virtual ~LexerNode() {}; int32_t m_tockenId; + int32_t getTockenId() { + return m_tockenId; + } int32_t m_startPos; - int32_t m_stopPos; int32_t getStartPos() { return m_startPos; } + int32_t m_stopPos; int32_t getStopPos() { return m_stopPos; } + virtual bool isNodeContainer() { + return false; + } }; class LexerNodeContainer : public LexerNode { public: @@ -44,6 +50,9 @@ namespace eci { } virtual ~LexerNodeContainer() {}; std::vector> m_list; + virtual bool isNodeContainer() { + return true; + } }; class LexerResult { private: @@ -78,13 +87,22 @@ namespace eci { int32_t getTockenId() { return m_tockenId; } - virtual std::vector> parse(const std::string& _data, int32_t _start, int32_t _stop)=0; + virtual std::vector> parse(const std::string& _data, int32_t _start, int32_t _stop) { + return std::vector>(); + }; + virtual void parseSection(std::vector>& _data) { + // nothing to do ... + }; + std::string getValue() { return m_regexValue; }; virtual bool isSubParse() { return false; } + virtual bool isSection() { + return false; + } }; class TypeBase : public Type { public: @@ -101,18 +119,22 @@ namespace eci { }; class TypeSection : public Type { public: - std::regex regexStart; - std::regex regexStop; - TypeSection(int32_t _tockenId, const std::string& _regexStart="", const std::string& _regexStop="") : + int32_t tockenStart; + int32_t tockenStop; + TypeSection(int32_t _tockenId, int32_t _tockenStart=-1, int32_t _tockenStop=-1) : Type(_tockenId), - regexStart(_regexStart, std::regex_constants::optimize | std::regex_constants::ECMAScript), - regexStop(_regexStop, std::regex_constants::optimize | std::regex_constants::ECMAScript) { - m_regexValue = _regexStart + " -> " + _regexStop; + tockenStart(_tockenStart), + tockenStop(_tockenStop) { + m_regexValue = "tok=" + etk::to_string(tockenStart) + " -> tok=" + etk::to_string(tockenStop); } virtual int32_t getType() { return TYPE_SECTION; } - std::vector> parse(const std::string& _data, int32_t _start, int32_t _stop); + virtual bool isSection() { + return true; + } + void parseSectionCurrent(std::vector>& _data); + void parseSection(std::vector>& _data); }; class TypeSubBase : public TypeBase { public: @@ -131,8 +153,8 @@ namespace eci { class TypeSubSection : public TypeSection { public: int32_t parrent; - TypeSubSection(int32_t _tockenId, int32_t _tokenIdParrent=-1, const std::string& _regexStart="", const std::string& _regexStop="") : - TypeSection(_tockenId, _regexStart, _regexStop), + TypeSubSection(int32_t _tockenId, int32_t _tokenIdParrent=-1, int32_t _tockenStart=-1, int32_t _tockenStop=-1) : + TypeSection(_tockenId, _tockenStart, _tockenStop), parrent(_tokenIdParrent) {} virtual int32_t getType() { return TYPE_SUB_SECTION; @@ -142,7 +164,7 @@ namespace eci { return true; } }; - std::map> m_searchList; + std::vector> m_searchList; public: Lexer(); ~Lexer(); @@ -155,10 +177,10 @@ namespace eci { /** * @brief Append a Token recognition (section reconise start and stop with counting the number of start and stop). * @param[in] _tokenId Tocken id value. - * @param[in] _regularExpressionStart reconise regular expression (start). - * @param[in] _regularExpressionStop reconise regular expression (stop). + * @param[in] _tockenStart Tocken start. + * @param[in] _tockenStop Tocken stop. */ - void appendSection(int32_t _tokenId, const std::string& _regularExpressionStart, const std::string& _regularExpressionStop); + void appendSection(int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop); /** * @brief Append a Token recognition (sub parsing). * @param[in] _tokenIdParrent parrent Tocken id value. @@ -170,10 +192,10 @@ namespace eci { * @brief Append a Token recognition (sub parsing) (section reconise start and stop with counting the number of start and stop). * @param[in] _tokenIdParrent parrent Tocken id value. * @param[in] _tokenId Tocken id value. - * @param[in] _regularExpressionStart reconise regular expression (start). - * @param[in] _regularExpressionStop reconise regular expression (stop). + * @param[in] _tockenStart Tocken start. + * @param[in] _tockenStop Tocken stop. */ - void appendSubSection(int32_t _tokenIdParrent, int32_t _tokenId, const std::string& _regularExpressionStart, const std::string& _regularExpressionStop); + void appendSubSection(int32_t _tokenIdParrent, int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop); LexerResult interprete(const std::string& _data); }; diff --git a/eci/Library.cpp b/eci/Library.cpp new file mode 100644 index 0000000..841db33 --- /dev/null +++ b/eci/Library.cpp @@ -0,0 +1,11 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include + diff --git a/eci/Library.h b/eci/Library.h new file mode 100644 index 0000000..fb4bee0 --- /dev/null +++ b/eci/Library.h @@ -0,0 +1,24 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_LIBRARY_H__ +#define __ECI_LIBRARY_H__ + +#include + +namespace eci { + class Library { + public: + Library() {}; + ~Library() {}; + protected: + std::string m_name; //!< library name (just for debug) + }; +} + +#endif diff --git a/eci/Type.cpp b/eci/Type.cpp new file mode 100644 index 0000000..be25105 --- /dev/null +++ b/eci/Type.cpp @@ -0,0 +1,11 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include + diff --git a/eci/Type.h b/eci/Type.h new file mode 100644 index 0000000..4939677 --- /dev/null +++ b/eci/Type.h @@ -0,0 +1,28 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_TYPE_H__ +#define __ECI_TYPE_H__ + +#include + +namespace eci { + class Type { + protected: + std::string m_signature; + public: + Type() {}; + ~Type() {}; + }; + template class TypeBase { + + }; + +} + +#endif \ No newline at end of file diff --git a/eci/Value.cpp b/eci/Value.cpp new file mode 100644 index 0000000..e69de29 diff --git a/eci/Value.h b/eci/Value.h new file mode 100644 index 0000000..37df354 --- /dev/null +++ b/eci/Value.h @@ -0,0 +1,26 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_VALUE_H__ +#define __ECI_VALUE_H__ + +#include +#include +#include + +namespace eci { + class Value : public std::enable_shared_from_this{ + public: + Value() {}; + ~Value() {}; + protected: + + }; +} + +#endif diff --git a/eci/Variable.cpp b/eci/Variable.cpp new file mode 100644 index 0000000..ecf2783 --- /dev/null +++ b/eci/Variable.cpp @@ -0,0 +1,20 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include + +eci::Variable::Variable() : + m_visibility(eci::visibilityPublic), + m_const(false) { + +} + +eci::Variable::~Variable() { + +} \ No newline at end of file diff --git a/eci/Variable.h b/eci/Variable.h new file mode 100644 index 0000000..da4968c --- /dev/null +++ b/eci/Variable.h @@ -0,0 +1,30 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_VARIABLE_H__ +#define __ECI_VARIABLE_H__ + +#include +#include +#include + + +namespace eci { + class Variable { + public: + Variable(); + ~Variable(); + private: + enum eci::visibility m_visibility; + bool m_const; + std::string m_name; + eci::Type m_type; + }; +} + +#endif diff --git a/eci/eci.cpp b/eci/eci.cpp index 066e31c..ef1c5d7 100644 --- a/eci/eci.cpp +++ b/eci/eci.cpp @@ -10,6 +10,7 @@ #include #include #include +#include int main(int argc, char** argv) { etk::log::setLevel(etk::log::logLevelDebug); @@ -19,12 +20,17 @@ int main(int argc, char** argv) { ECI_CRITICAL("need the file to parse"); return -1; } - eci::ParserCpp tmpParser; + //eci::ParserCpp tmpParser; //std::string data = "/* plop */ \n int eee = 22; // error value \nint main(void) {\n return 0;\n}\n";//etk::FSNodeReadAllData(argv[1]); //std::string data = "alpha /* plop */ test"; //std::string data = "pp \n // qdfqdfsdf \nde"; //tmpParser.parse(data); - tmpParser.parse(etk::FSNodeReadAllData(argv[1])); + //tmpParser.parse(etk::FSNodeReadAllData(argv[1])); + + eci::Interpreter::Interpreter virtualMachine; + virtualMachine.addFile(argv[1]); + + virtualMachine.main(); return 0; } \ No newline at end of file diff --git a/eci/lang/ParserCpp.cpp b/eci/lang/ParserCpp.cpp index ab1d19f..ea7dfd8 100644 --- a/eci/lang/ParserCpp.cpp +++ b/eci/lang/ParserCpp.cpp @@ -9,43 +9,6 @@ #include #include -enum cppTokenList { - tokenCppCommentMultiline, - tokenCppCommentSingleLine, - tokenCppPreProcessor, - tokenCppPreProcessorIf, - tokenCppPreProcessorElse, - tokenCppPreProcessorEndif, - tokenCppPreProcessorIfdef, - tokenCppPreProcessorIfndef, - tokenCppPreProcessorDefine, - tokenCppPreProcessorWarning, - tokenCppPreProcessorError, - tokenCppPreProcessorInclude, - tokenCppPreProcessorImport, - tokenCppPreProcessorSectionPthese, - - tokenCppStringDoubleQuote, - tokenCppStringSimpleQuote, - tokenCppSectionBrace, - tokenCppSectionPthese, - tokenCppSectionHook, - tokenCppBranch, - tokenCppSystem, - tokenCppType, - tokenCppVisibility, - tokenCppContener, - tokenCppTypeDef, - tokenCppAuto, - tokenCppNullptr, - tokenCppSystemDefine, - tokenCppNumericValue, - tokenCppBoolean, - tokenCppCondition, - tokenCppAssignation, - tokenCppString, - tokenCppSeparator, -}; eci::ParserCpp::ParserCpp() { m_lexer.append(tokenCppCommentMultiline, "/\\*(.|\\r|\\n)*?(\\*/|\\0)"); @@ -61,12 +24,15 @@ eci::ParserCpp::ParserCpp() { m_lexer.appendSub(tokenCppPreProcessor, tokenCppPreProcessorError, "\\berror\\b"); m_lexer.appendSub(tokenCppPreProcessor, tokenCppPreProcessorInclude, "\\binclude\\b"); m_lexer.appendSub(tokenCppPreProcessor, tokenCppPreProcessorImport, "\\bimport\\b"); // specific to c++ interpreted - m_lexer.appendSubSection(tokenCppPreProcessor, tokenCppPreProcessorSectionPthese, "\\(", "\\)"); + //m_lexer.appendSubSection(tokenCppPreProcessor, tokenCppPreProcessorSectionPthese, "\\(", "\\)"); m_lexer.append(tokenCppStringDoubleQuote, "\"(.|\\\\[\\\\\"])*?\""); m_lexer.append(tokenCppStringSimpleQuote, "'\\?.'"); - m_lexer.appendSection(tokenCppSectionBrace, "\\{", "\\}"); - m_lexer.appendSection(tokenCppSectionPthese, "\\(", "\\)"); - m_lexer.appendSection(tokenCppSectionHook, "\\[", "\\]"); + m_lexer.append(tokenCppBraceIn, "\\{"); + m_lexer.append(tokenCppBraceOut, "\\}"); + m_lexer.append(tokenCppPtheseIn, "\\("); + m_lexer.append(tokenCppPtheseOut, "\\)"); + m_lexer.append(tokenCppHookIn, "\\["); + m_lexer.append(tokenCppHookOut, "\\]"); m_lexer.append(tokenCppBranch, "\\b(return|goto|if|else|case|default|break|continue|while|do|for)\\b"); m_lexer.append(tokenCppSystem, "\\b(new|delete|try|catch)\\b"); m_lexer.append(tokenCppType, "\\b(bool|char(16_t|32_t)?|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void|(I|U)(8|16|32|64|128))\\b"); @@ -79,21 +45,50 @@ eci::ParserCpp::ParserCpp() { m_lexer.append(tokenCppNumericValue, "\\b(((0(x|X)[0-9a-fA-F]*)|(\\d+\\.?\\d*|\\.\\d+)((e|E)(\\+|\\-)?\\d+)?)(L|l|UL|ul|u|U|F|f)?)\\b"); m_lexer.append(tokenCppBoolean, "\\b(true|false)\\b"); m_lexer.append(tokenCppCondition, "==|>=|<=|!=|<|>|&&|\\|\\|"); - m_lexer.append(tokenCppAssignation, "(=|\\*|/|-|+|&)"); + m_lexer.append(tokenCppAssignation, "(\\+=|-=|\\*=|/=|=|\\*|/|--|-|\\+\\+|\\+|&)"); m_lexer.append(tokenCppString, "\\w+"); m_lexer.append(tokenCppSeparator, "(;|,|::|:)"); + m_lexer.appendSection(tokenCppSectionBrace, tokenCppBraceIn, tokenCppBraceOut); + m_lexer.appendSection(tokenCppSectionPthese, tokenCppPtheseIn, tokenCppPtheseOut); + m_lexer.appendSection(tokenCppSectionHook, tokenCppHookIn, tokenCppHookOut); } eci::ParserCpp::~ParserCpp() { } +static void printNode(const std::string& _data, const std::vector>& _nodes, int32_t _level=0) { + std::string offset; + for (int32_t iii=0; iii<_level; ++iii) { + offset += " "; + } + for (auto &it : _nodes) { + if (it->isNodeContainer() == true) { + std::shared_ptr sec = std::dynamic_pointer_cast(it); + if (sec != nullptr) { + ECI_INFO(offset << " " << it->getStartPos() << "->" << it->getStopPos() << " (container)"); + printNode(_data, sec->m_list, _level+1); + } + } else { + ECI_INFO(offset << it->getStartPos() << "->" << it->getStopPos() << " data='" <getStartPos(), it->getStopPos()-it->getStartPos()) << "'" ); + } + } +} + bool eci::ParserCpp::parse(const std::string& _data) { m_result = m_lexer.interprete(_data); - ECI_INFO("find :"); + + // TODO: Agregate type + // TODO: Agregate Action + // TODO: Agregate Function + + ECI_INFO("find :"); + printNode(_data, m_result.m_list); + /* for (auto &it : m_result.m_list) { ECI_INFO(" start=" << it->getStartPos() << " stop=" << it->getStopPos() << " data='" <getStartPos(), it->getStopPos()-it->getStartPos()) << "'" ); } + */ return false; } diff --git a/eci/lang/ParserCpp.h b/eci/lang/ParserCpp.h index ed41098..654e059 100644 --- a/eci/lang/ParserCpp.h +++ b/eci/lang/ParserCpp.h @@ -12,8 +12,52 @@ #include namespace eci { + + enum cppTokenList { + tokenCppCommentMultiline, + tokenCppCommentSingleLine, + tokenCppPreProcessor, + tokenCppPreProcessorIf, + tokenCppPreProcessorElse, + tokenCppPreProcessorEndif, + tokenCppPreProcessorIfdef, + tokenCppPreProcessorIfndef, + tokenCppPreProcessorDefine, + tokenCppPreProcessorWarning, + tokenCppPreProcessorError, + tokenCppPreProcessorInclude, + tokenCppPreProcessorImport, + tokenCppPreProcessorSectionPthese, + + tokenCppStringDoubleQuote, + tokenCppStringSimpleQuote, + tokenCppBraceIn, + tokenCppBraceOut, + tokenCppPtheseIn, + tokenCppPtheseOut, + tokenCppHookIn, + tokenCppHookOut, + tokenCppSectionBrace, + tokenCppSectionPthese, + tokenCppSectionHook, + tokenCppBranch, + tokenCppSystem, + tokenCppType, + tokenCppVisibility, + tokenCppContener, + tokenCppTypeDef, + tokenCppAuto, + tokenCppNullptr, + tokenCppSystemDefine, + tokenCppNumericValue, + tokenCppBoolean, + tokenCppCondition, + tokenCppAssignation, + tokenCppString, + tokenCppSeparator, + }; class ParserCpp { - private: + public: eci::Lexer m_lexer; eci::LexerResult m_result; public: diff --git a/eci/visibility.h b/eci/visibility.h new file mode 100644 index 0000000..86dc258 --- /dev/null +++ b/eci/visibility.h @@ -0,0 +1,23 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2014, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __ECI_VISIBILITY_H__ +#define __ECI_VISIBILITY_H__ + +#include + +namespace eci { + enum visibility { + visibilityNone, + visibilityPrivate, + visibilityProtected, + visibilityPublic, + }; +} + +#endif diff --git a/lutin_eci2.py b/lutin_eci2.py index 70831ff..af1ee3b 100644 --- a/lutin_eci2.py +++ b/lutin_eci2.py @@ -17,6 +17,15 @@ def create(target): 'eci/eci.cpp', 'eci/Lexer.cpp', 'eci/debug.cpp', + 'eci/Class.cpp', + 'eci/Enum.cpp', + 'eci/File.cpp', + 'eci/Function.cpp', + 'eci/Interpreter.cpp', + 'eci/Library.cpp', + 'eci/Type.cpp', + 'eci/Variable.cpp', + 'eci/Value.cpp', 'eci/lang/ParserCpp.cpp' ]) myModule.add_export_path(tools.get_current_path(__file__)) diff --git a/tests/01_comment.c b/tests/01_comment.c index 406305d..952ab54 100644 --- a/tests/01_comment.c +++ b/tests/01_comment.c @@ -1,11 +1,11 @@ #include -printf("Hello\n"); -printf("Hello\n"); /* this is a comment */ printf("Hello\n"); -printf("Hello\n"); +printf("Hello 1\n"); +printf("Hello 2\n"); /* this is a comment */ printf("Hello 3\n"); +printf("Hello 4\n"); // this is also a comment sayhello(); -printf("Hello\n"); -printf("Hello\n"); /* this is a second comment */ printf("Hello\n"); +printf("Hello 5\n"); +printf("Hello 6\n"); /* this is a second comment */ printf("Hello 7\n"); void main() {} diff --git a/tests/01_comment.expect b/tests/01_comment.expect index b1387ad..c8d7b96 100644 --- a/tests/01_comment.expect +++ b/tests/01_comment.expect @@ -1,5 +1,7 @@ -Hello -Hello -Hello -Hello -Hello +Hello 1 +Hello 2 +Hello 3 +Hello 4 +Hello 5 +Hello 6 +Hello 7 diff --git a/tests/55_section.c b/tests/55_section.c new file mode 100644 index 0000000..55ce31f --- /dev/null +++ b/tests/55_section.c @@ -0,0 +1,12 @@ +//#include + +int main(int argc, char* argv[]) { + int32_t aaa = 0; + int32_t bbb = 0; + if ( aaa == bbb && (aaa & bbb) != 0) { + for (int32_t iii=0; iii< 562; ++iii) { + aaa+= 1.0; + } + } + return -1; +}