[DEV] start thingking of the architecture of interpretor
This commit is contained in:
parent
3b85d09ffa
commit
a5e126fde2
11
eci/Class.cpp
Normal file
11
eci/Class.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE-2 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eci/Class.h>
|
||||||
|
#include <eci/debug.h>
|
||||||
|
|
22
eci/Class.h
Normal file
22
eci/Class.h
Normal file
@ -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 <etk/types.h>
|
||||||
|
|
||||||
|
namespace eci {
|
||||||
|
class Class {
|
||||||
|
public:
|
||||||
|
Class() {};
|
||||||
|
~Class() {};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
62
eci/Enum.cpp
Normal file
62
eci/Enum.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE-2 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eci/Enum.h>
|
||||||
|
#include <eci/debug.h>
|
||||||
|
|
||||||
|
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<m_values.size(); ++iii) {
|
||||||
|
if (m_values[iii].first == _name) {
|
||||||
|
ECI_ERROR("Enum name already exist ... : " << _name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastValue = m_values[iii].second;
|
||||||
|
}
|
||||||
|
m_values.push_back(std::make_pair(_name, lastValue+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void eci::Enum::addValue(const std::string& _name, int32_t _value) {
|
||||||
|
if (m_values.size() == 0) {
|
||||||
|
m_values.push_back(std::make_pair(_name, _value));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (size_t iii=0; iii<m_values.size(); ++iii) {
|
||||||
|
if (m_values[iii].first == _name) {
|
||||||
|
ECI_ERROR("Enum name already exist ... : " << _name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_values.push_back(std::make_pair(_name, _value));
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t eci::Enum::getValue(const std::string& _name) const {
|
||||||
|
for (size_t iii=0; iii<m_values.size(); ++iii) {
|
||||||
|
if (m_values[iii].first == _name) {
|
||||||
|
return m_values[iii].second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ECI_ERROR("Enum name does not exist ... : '" << _name << "'");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& eci::Enum::getName(int32_t _value) const {
|
||||||
|
for (size_t iii=0; iii<m_values.size(); ++iii) {
|
||||||
|
if (m_values[iii].second == _value) {
|
||||||
|
return m_values[iii].first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ECI_ERROR("Enum name does not exist ... : '" << _value << "'");
|
||||||
|
static const std::string errorValue = "---UnknowName---";
|
||||||
|
return errorValue;
|
||||||
|
}
|
||||||
|
|
29
eci/Enum.h
Normal file
29
eci/Enum.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE-2 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ECI_ENUM_H__
|
||||||
|
#define __ECI_ENUM_H__
|
||||||
|
|
||||||
|
#include <etk/types.h>
|
||||||
|
|
||||||
|
namespace eci {
|
||||||
|
class Enum {
|
||||||
|
public:
|
||||||
|
Enum() {};
|
||||||
|
~Enum() {};
|
||||||
|
protected:
|
||||||
|
std::vector<std::pair<std::string, int32_t>> 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
|
39
eci/File.cpp
Normal file
39
eci/File.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE-2 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eci/File.h>
|
||||||
|
#include <eci/debug.h>
|
||||||
|
#include <etk/os/FSNode.h>
|
||||||
|
#include <eci/lang/ParserCpp.h>
|
||||||
|
|
||||||
|
|
||||||
|
static std::string getValue(const std::string& _file, const std::shared_ptr<eci::LexerNode>& _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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
29
eci/File.h
Normal file
29
eci/File.h
Normal file
@ -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 <etk/types.h>
|
||||||
|
#include <eci/Class.h>
|
||||||
|
#include <eci/Enum.h>
|
||||||
|
#include <eci/Variable.h>
|
||||||
|
#include <eci/Function.h>
|
||||||
|
|
||||||
|
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
|
28
eci/Function.cpp
Normal file
28
eci/Function.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE-2 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eci/Function.h>
|
||||||
|
#include <eci/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
eci::Function::Function() :
|
||||||
|
m_const(false),
|
||||||
|
m_static(false),
|
||||||
|
m_visibility(eci::visibilityPublic){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
eci::Function::~Function() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<eci::Value>> eci::Function::call(const std::vector<std::shared_ptr<eci::Value>>& _input) {
|
||||||
|
return std::vector<std::shared_ptr<eci::Value>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
35
eci/Function.h
Normal file
35
eci/Function.h
Normal file
@ -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 <etk/types.h>
|
||||||
|
#include <eci/visibility.h>
|
||||||
|
#include <eci/Variable.h>
|
||||||
|
#include <eci/Value.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
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<eci::Variable> m_return; //!< return value.
|
||||||
|
std::vector<eci::Variable> m_arguments; //!< return value.
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<eci::Value>> call(const std::vector<std::shared_ptr<eci::Value>>& _input);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
29
eci/Interpreter.cpp
Normal file
29
eci/Interpreter.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE-2 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eci/Interpreter.h>
|
||||||
|
#include <eci/debug.h>
|
||||||
|
|
||||||
|
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 ... ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
30
eci/Interpreter.h
Normal file
30
eci/Interpreter.h
Normal file
@ -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 <etk/types.h>
|
||||||
|
#include <eci/Library.h>
|
||||||
|
#include <eci/File.h>
|
||||||
|
|
||||||
|
namespace eci {
|
||||||
|
class Interpreter {
|
||||||
|
public:
|
||||||
|
Interpreter();
|
||||||
|
~Interpreter();
|
||||||
|
protected:
|
||||||
|
std::vector<eci::Library> m_libraries; //!< list of all loaded libraries.
|
||||||
|
std::vector<eci::File> m_files; //!< List of all files in the current program.
|
||||||
|
public:
|
||||||
|
void addFile(const std::string& _filename);
|
||||||
|
void main();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
190
eci/Lexer.cpp
190
eci/Lexer.cpp
@ -18,38 +18,38 @@ eci::Lexer::~Lexer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void eci::Lexer::append(int32_t _tokenId, const std::string& _regularExpression) {
|
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 {
|
try {
|
||||||
m_searchList.insert(std::make_pair(_tokenId, std::make_shared<eci::Lexer::TypeBase>(_tokenId, _regularExpression)));
|
m_searchList.push_back(std::make_shared<eci::Lexer::TypeBase>(_tokenId, _regularExpression));
|
||||||
} catch (std::exception e){
|
} catch (std::exception e){
|
||||||
ECI_ERROR(" create reg exp : '" << _regularExpression << "' : what:" << e.what());
|
ECI_ERROR(" create reg exp : '" << _regularExpression << "' : what:" << e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void eci::Lexer::appendSection(int32_t _tokenId, const std::string& _regularExpressionStart, const std::string& _regularExpressionStop) {
|
void eci::Lexer::appendSection(int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop) {
|
||||||
ECI_INFO("CPP lexer add section : '" << _regularExpressionStart << "' .. '" << _regularExpressionStop << "'");
|
ECI_INFO("CPP lexer add section [" << _tokenId << "] : '" << _tockenStart << "' .. '" << _tockenStop << "'");
|
||||||
try {
|
try {
|
||||||
m_searchList.insert(std::make_pair(_tokenId, std::make_shared<eci::Lexer::TypeSection>(_tokenId, _regularExpressionStart, _regularExpressionStop)));
|
m_searchList.push_back(std::make_shared<eci::Lexer::TypeSection>(_tokenId, _tockenStart, _tockenStop));
|
||||||
} catch (std::exception e){
|
} 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) {
|
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 {
|
try {
|
||||||
m_searchList.insert(std::make_pair(_tokenId, std::make_shared<eci::Lexer::TypeSubBase>(_tokenId, _tokenIdParrent, _regularExpression)));
|
m_searchList.push_back(std::make_shared<eci::Lexer::TypeSubBase>(_tokenId, _tokenIdParrent, _regularExpression));
|
||||||
} catch (std::exception e){
|
} catch (std::exception e){
|
||||||
ECI_ERROR(" create reg exp : '" << _regularExpression << "' : what:" << e.what());
|
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) {
|
void eci::Lexer::appendSubSection(int32_t _tokenIdParrent, int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop) {
|
||||||
ECI_INFO("CPP lexer add section sub : [" << _tokenIdParrent << "] '" << _regularExpressionStart << "' .. '" << _regularExpressionStop << "'");
|
ECI_INFO("CPP lexer add section sub : [" << _tokenId << "] [" << _tokenIdParrent << "] '" << _tockenStart << "' .. '" << _tockenStop << "'");
|
||||||
try {
|
try {
|
||||||
m_searchList.insert(std::make_pair(_tokenId, std::make_shared<eci::Lexer::TypeSubSection>(_tokenId, _tokenIdParrent, _regularExpressionStart, _regularExpressionStop)));
|
m_searchList.push_back(std::make_shared<eci::Lexer::TypeSubSection>(_tokenId, _tokenIdParrent, _tockenStart, _tockenStop));
|
||||||
} catch (std::exception e){
|
} 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);
|
ECI_INFO("Parse : \n" << _data);
|
||||||
for (auto &it : m_searchList) {
|
for (auto &it : m_searchList) {
|
||||||
//ECI_INFO("Parse RegEx : " << it.first << " : " << it.second.getRegExDecorated());
|
//ECI_INFO("Parse RegEx : " << it.first << " : " << it.second.getRegExDecorated());
|
||||||
if (it.second == nullptr) {
|
if (it == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (it.second->isSubParse() == true) {
|
if (it->isSubParse() == true) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (result.m_list.size() == 0) {
|
if (it->isSection() == false) {
|
||||||
result.m_list = it.second->parse(_data, 0, _data.size());
|
if (result.m_list.size() == 0) {
|
||||||
} else {
|
result.m_list = it->parse(_data, 0, _data.size());
|
||||||
int32_t start = 0;
|
} else {
|
||||||
auto itList(result.m_list.begin());
|
int32_t start = 0;
|
||||||
while (itList != result.m_list.end()) {
|
auto itList(result.m_list.begin());
|
||||||
if (*itList == nullptr) {
|
while (itList != result.m_list.end()) {
|
||||||
ECI_TODO("remove null shared_ptr");
|
if (*itList == nullptr) {
|
||||||
++itList;
|
ECI_TODO("remove null shared_ptr");
|
||||||
continue;
|
++itList;
|
||||||
}
|
continue;
|
||||||
if ((*itList)->getStartPos() == start) {
|
}
|
||||||
// nothing to do ..
|
if ((*itList)->getStartPos() == start) {
|
||||||
|
// nothing to do ..
|
||||||
|
start = (*itList)->getStopPos();
|
||||||
|
++itList;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::vector<std::shared_ptr<eci::LexerNode>> 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();
|
start = (*itList)->getStopPos();
|
||||||
++itList;
|
++itList;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
std::vector<std::shared_ptr<eci::LexerNode>> res = it.second->parse(_data, start, (*itList)->getStartPos());
|
// Do the last element :
|
||||||
// append it in the buffer:
|
if (start < _data.size()) {
|
||||||
if (res.size() > 0) {
|
std::vector<std::shared_ptr<eci::LexerNode>> res = it->parse(_data, start, _data.size());
|
||||||
int32_t currentPos = std::distance(result.m_list.begin(), itList) + res.size() ;
|
for (auto &itRes : res) {
|
||||||
result.m_list.insert(itList, res.begin(), res.end());
|
result.m_list.push_back(itRes);
|
||||||
itList = result.m_list.begin() + currentPos;
|
}
|
||||||
}
|
|
||||||
start = (*itList)->getStopPos();
|
|
||||||
++itList;
|
|
||||||
}
|
|
||||||
// Do the last element :
|
|
||||||
if (start < _data.size()) {
|
|
||||||
std::vector<std::shared_ptr<eci::LexerNode>> res = it.second->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;
|
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<std::shared_ptr<eci::LexerNode>> eci::Lexer::TypeBase::parse(const std::string& _data, int32_t _start, int32_t _stop) {
|
std::vector<std::shared_ptr<eci::LexerNode>> eci::Lexer::TypeBase::parse(const std::string& _data, int32_t _start, int32_t _stop) {
|
||||||
std::vector<std::shared_ptr<eci::LexerNode>> result;
|
std::vector<std::shared_ptr<eci::LexerNode>> result;
|
||||||
ECI_DEBUG("parse : " << getValue());
|
ECI_VERBOSE("parse : " << getValue());
|
||||||
while (true) {
|
while (true) {
|
||||||
std::smatch resultMatch;
|
std::smatch resultMatch;
|
||||||
std::regex_constants::match_flag_type flags = std::regex_constants::match_any;
|
std::regex_constants::match_flag_type flags = createFlags(_data, _start, _stop);
|
||||||
//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_search(_data.begin()+_start, _data.begin()+_stop, resultMatch, regex, flags);
|
std::regex_search(_data.begin()+_start, _data.begin()+_stop, resultMatch, regex, flags);
|
||||||
if (resultMatch.size() > 0) {
|
if (resultMatch.size() > 0) {
|
||||||
int32_t start = std::distance(_data.begin(), resultMatch[0].first);
|
int32_t start = std::distance(_data.begin(), resultMatch[0].first);
|
||||||
int32_t stop = std::distance(_data.begin(), resultMatch[0].second);
|
int32_t stop = std::distance(_data.begin(), resultMatch[0].second);
|
||||||
ECI_DEBUG(" find data at : start=" << start << " stop=" << stop << " data='" <<std::string(_data, start, stop-start) << "'" );
|
ECI_VERBOSE(" find data at : start=" << start << " stop=" << stop << " data='" <<std::string(_data, start, stop-start) << "'" );
|
||||||
_start = stop;
|
_start = stop;
|
||||||
result.push_back(std::make_shared<eci::LexerNode>(m_tockenId, start, stop));
|
result.push_back(std::make_shared<eci::LexerNode>(m_tockenId, start, stop));
|
||||||
} else {
|
} else {
|
||||||
@ -142,10 +154,52 @@ std::vector<std::shared_ptr<eci::LexerNode>> eci::Lexer::TypeBase::parse(const s
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<eci::LexerNode>> eci::Lexer::TypeSection::parse(const std::string& _data, int32_t _start, int32_t _stop) {
|
void eci::Lexer::TypeSection::parseSectionCurrent(std::vector<std::shared_ptr<eci::LexerNode>>& _data) {
|
||||||
std::vector<std::shared_ptr<eci::LexerNode>> result;
|
std::vector<size_t> posList;
|
||||||
ECI_TODO("later 1");
|
for (size_t iii=0; iii<_data.size(); ++iii) {
|
||||||
return result;
|
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<eci::LexerNodeContainer> newContainer = std::make_shared<eci::LexerNodeContainer>(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<std::shared_ptr<eci::LexerNode>>& _data) {
|
||||||
|
ECI_VERBOSE("parse section : " << getValue());
|
||||||
|
for (auto &it : _data) {
|
||||||
|
if (it == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (it->isNodeContainer() == true) {
|
||||||
|
std::shared_ptr<eci::LexerNodeContainer> sec = std::dynamic_pointer_cast<eci::LexerNodeContainer>(it);
|
||||||
|
parseSection(sec->m_list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parseSectionCurrent(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<eci::LexerNode>> eci::Lexer::TypeSubBase::parse(const std::string& _data, int32_t _start, int32_t _stop) {
|
std::vector<std::shared_ptr<eci::LexerNode>> eci::Lexer::TypeSubBase::parse(const std::string& _data, int32_t _start, int32_t _stop) {
|
||||||
|
58
eci/Lexer.h
58
eci/Lexer.h
@ -27,14 +27,20 @@ namespace eci {
|
|||||||
}
|
}
|
||||||
virtual ~LexerNode() {};
|
virtual ~LexerNode() {};
|
||||||
int32_t m_tockenId;
|
int32_t m_tockenId;
|
||||||
|
int32_t getTockenId() {
|
||||||
|
return m_tockenId;
|
||||||
|
}
|
||||||
int32_t m_startPos;
|
int32_t m_startPos;
|
||||||
int32_t m_stopPos;
|
|
||||||
int32_t getStartPos() {
|
int32_t getStartPos() {
|
||||||
return m_startPos;
|
return m_startPos;
|
||||||
}
|
}
|
||||||
|
int32_t m_stopPos;
|
||||||
int32_t getStopPos() {
|
int32_t getStopPos() {
|
||||||
return m_stopPos;
|
return m_stopPos;
|
||||||
}
|
}
|
||||||
|
virtual bool isNodeContainer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class LexerNodeContainer : public LexerNode {
|
class LexerNodeContainer : public LexerNode {
|
||||||
public:
|
public:
|
||||||
@ -44,6 +50,9 @@ namespace eci {
|
|||||||
}
|
}
|
||||||
virtual ~LexerNodeContainer() {};
|
virtual ~LexerNodeContainer() {};
|
||||||
std::vector<std::shared_ptr<eci::LexerNode>> m_list;
|
std::vector<std::shared_ptr<eci::LexerNode>> m_list;
|
||||||
|
virtual bool isNodeContainer() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class LexerResult {
|
class LexerResult {
|
||||||
private:
|
private:
|
||||||
@ -78,13 +87,22 @@ namespace eci {
|
|||||||
int32_t getTockenId() {
|
int32_t getTockenId() {
|
||||||
return m_tockenId;
|
return m_tockenId;
|
||||||
}
|
}
|
||||||
virtual std::vector<std::shared_ptr<eci::LexerNode>> parse(const std::string& _data, int32_t _start, int32_t _stop)=0;
|
virtual std::vector<std::shared_ptr<eci::LexerNode>> parse(const std::string& _data, int32_t _start, int32_t _stop) {
|
||||||
|
return std::vector<std::shared_ptr<eci::LexerNode>>();
|
||||||
|
};
|
||||||
|
virtual void parseSection(std::vector<std::shared_ptr<eci::LexerNode>>& _data) {
|
||||||
|
// nothing to do ...
|
||||||
|
};
|
||||||
|
|
||||||
std::string getValue() {
|
std::string getValue() {
|
||||||
return m_regexValue;
|
return m_regexValue;
|
||||||
};
|
};
|
||||||
virtual bool isSubParse() {
|
virtual bool isSubParse() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
virtual bool isSection() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class TypeBase : public Type {
|
class TypeBase : public Type {
|
||||||
public:
|
public:
|
||||||
@ -101,18 +119,22 @@ namespace eci {
|
|||||||
};
|
};
|
||||||
class TypeSection : public Type {
|
class TypeSection : public Type {
|
||||||
public:
|
public:
|
||||||
std::regex regexStart;
|
int32_t tockenStart;
|
||||||
std::regex regexStop;
|
int32_t tockenStop;
|
||||||
TypeSection(int32_t _tockenId, const std::string& _regexStart="", const std::string& _regexStop="") :
|
TypeSection(int32_t _tockenId, int32_t _tockenStart=-1, int32_t _tockenStop=-1) :
|
||||||
Type(_tockenId),
|
Type(_tockenId),
|
||||||
regexStart(_regexStart, std::regex_constants::optimize | std::regex_constants::ECMAScript),
|
tockenStart(_tockenStart),
|
||||||
regexStop(_regexStop, std::regex_constants::optimize | std::regex_constants::ECMAScript) {
|
tockenStop(_tockenStop) {
|
||||||
m_regexValue = _regexStart + " -> " + _regexStop;
|
m_regexValue = "tok=" + etk::to_string(tockenStart) + " -> tok=" + etk::to_string(tockenStop);
|
||||||
}
|
}
|
||||||
virtual int32_t getType() {
|
virtual int32_t getType() {
|
||||||
return TYPE_SECTION;
|
return TYPE_SECTION;
|
||||||
}
|
}
|
||||||
std::vector<std::shared_ptr<eci::LexerNode>> parse(const std::string& _data, int32_t _start, int32_t _stop);
|
virtual bool isSection() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void parseSectionCurrent(std::vector<std::shared_ptr<eci::LexerNode>>& _data);
|
||||||
|
void parseSection(std::vector<std::shared_ptr<eci::LexerNode>>& _data);
|
||||||
};
|
};
|
||||||
class TypeSubBase : public TypeBase {
|
class TypeSubBase : public TypeBase {
|
||||||
public:
|
public:
|
||||||
@ -131,8 +153,8 @@ namespace eci {
|
|||||||
class TypeSubSection : public TypeSection {
|
class TypeSubSection : public TypeSection {
|
||||||
public:
|
public:
|
||||||
int32_t parrent;
|
int32_t parrent;
|
||||||
TypeSubSection(int32_t _tockenId, int32_t _tokenIdParrent=-1, const std::string& _regexStart="", const std::string& _regexStop="") :
|
TypeSubSection(int32_t _tockenId, int32_t _tokenIdParrent=-1, int32_t _tockenStart=-1, int32_t _tockenStop=-1) :
|
||||||
TypeSection(_tockenId, _regexStart, _regexStop),
|
TypeSection(_tockenId, _tockenStart, _tockenStop),
|
||||||
parrent(_tokenIdParrent) {}
|
parrent(_tokenIdParrent) {}
|
||||||
virtual int32_t getType() {
|
virtual int32_t getType() {
|
||||||
return TYPE_SUB_SECTION;
|
return TYPE_SUB_SECTION;
|
||||||
@ -142,7 +164,7 @@ namespace eci {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::map<int32_t, std::shared_ptr<eci::Lexer::Type>> m_searchList;
|
std::vector<std::shared_ptr<eci::Lexer::Type>> m_searchList;
|
||||||
public:
|
public:
|
||||||
Lexer();
|
Lexer();
|
||||||
~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).
|
* @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] _tokenId Tocken id value.
|
||||||
* @param[in] _regularExpressionStart reconise regular expression (start).
|
* @param[in] _tockenStart Tocken start.
|
||||||
* @param[in] _regularExpressionStop reconise regular expression (stop).
|
* @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).
|
* @brief Append a Token recognition (sub parsing).
|
||||||
* @param[in] _tokenIdParrent parrent Tocken id value.
|
* @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).
|
* @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] _tokenIdParrent parrent Tocken id value.
|
||||||
* @param[in] _tokenId Tocken id value.
|
* @param[in] _tokenId Tocken id value.
|
||||||
* @param[in] _regularExpressionStart reconise regular expression (start).
|
* @param[in] _tockenStart Tocken start.
|
||||||
* @param[in] _regularExpressionStop reconise regular expression (stop).
|
* @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);
|
LexerResult interprete(const std::string& _data);
|
||||||
};
|
};
|
||||||
|
11
eci/Library.cpp
Normal file
11
eci/Library.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE-2 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eci/Library.h>
|
||||||
|
#include <eci/debug.h>
|
||||||
|
|
24
eci/Library.h
Normal file
24
eci/Library.h
Normal file
@ -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 <etk/types.h>
|
||||||
|
|
||||||
|
namespace eci {
|
||||||
|
class Library {
|
||||||
|
public:
|
||||||
|
Library() {};
|
||||||
|
~Library() {};
|
||||||
|
protected:
|
||||||
|
std::string m_name; //!< library name (just for debug)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
11
eci/Type.cpp
Normal file
11
eci/Type.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE-2 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eci/Type.h>
|
||||||
|
#include <eci/debug.h>
|
||||||
|
|
28
eci/Type.h
Normal file
28
eci/Type.h
Normal file
@ -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 <etk/types.h>
|
||||||
|
|
||||||
|
namespace eci {
|
||||||
|
class Type {
|
||||||
|
protected:
|
||||||
|
std::string m_signature;
|
||||||
|
public:
|
||||||
|
Type() {};
|
||||||
|
~Type() {};
|
||||||
|
};
|
||||||
|
template<typename T> class TypeBase {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
0
eci/Value.cpp
Normal file
0
eci/Value.cpp
Normal file
26
eci/Value.h
Normal file
26
eci/Value.h
Normal file
@ -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 <etk/types.h>
|
||||||
|
#include <eci/Type.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace eci {
|
||||||
|
class Value : public std::enable_shared_from_this<Value>{
|
||||||
|
public:
|
||||||
|
Value() {};
|
||||||
|
~Value() {};
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
20
eci/Variable.cpp
Normal file
20
eci/Variable.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE-2 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eci/Variable.h>
|
||||||
|
#include <eci/debug.h>
|
||||||
|
|
||||||
|
eci::Variable::Variable() :
|
||||||
|
m_visibility(eci::visibilityPublic),
|
||||||
|
m_const(false) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
eci::Variable::~Variable() {
|
||||||
|
|
||||||
|
}
|
30
eci/Variable.h
Normal file
30
eci/Variable.h
Normal file
@ -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 <etk/types.h>
|
||||||
|
#include <eci/visibility.h>
|
||||||
|
#include <eci/Type.h>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
10
eci/eci.cpp
10
eci/eci.cpp
@ -10,6 +10,7 @@
|
|||||||
#include <eci/debug.h>
|
#include <eci/debug.h>
|
||||||
#include <eci/lang/ParserCpp.h>
|
#include <eci/lang/ParserCpp.h>
|
||||||
#include <etk/os/FSNode.h>
|
#include <etk/os/FSNode.h>
|
||||||
|
#include <eci/Interpreter.h>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
etk::log::setLevel(etk::log::logLevelDebug);
|
etk::log::setLevel(etk::log::logLevelDebug);
|
||||||
@ -19,12 +20,17 @@ int main(int argc, char** argv) {
|
|||||||
ECI_CRITICAL("need the file to parse");
|
ECI_CRITICAL("need the file to parse");
|
||||||
return -1;
|
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 = "/* 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 = "alpha /* plop */ test";
|
||||||
//std::string data = "pp \n // qdfqdfsdf \nde";
|
//std::string data = "pp \n // qdfqdfsdf \nde";
|
||||||
//tmpParser.parse(data);
|
//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;
|
return 0;
|
||||||
}
|
}
|
@ -9,43 +9,6 @@
|
|||||||
#include <eci/lang/ParserCpp.h>
|
#include <eci/lang/ParserCpp.h>
|
||||||
#include <eci/debug.h>
|
#include <eci/debug.h>
|
||||||
|
|
||||||
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() {
|
eci::ParserCpp::ParserCpp() {
|
||||||
m_lexer.append(tokenCppCommentMultiline, "/\\*(.|\\r|\\n)*?(\\*/|\\0)");
|
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, tokenCppPreProcessorError, "\\berror\\b");
|
||||||
m_lexer.appendSub(tokenCppPreProcessor, tokenCppPreProcessorInclude, "\\binclude\\b");
|
m_lexer.appendSub(tokenCppPreProcessor, tokenCppPreProcessorInclude, "\\binclude\\b");
|
||||||
m_lexer.appendSub(tokenCppPreProcessor, tokenCppPreProcessorImport, "\\bimport\\b"); // specific to c++ interpreted
|
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(tokenCppStringDoubleQuote, "\"(.|\\\\[\\\\\"])*?\"");
|
||||||
m_lexer.append(tokenCppStringSimpleQuote, "'\\?.'");
|
m_lexer.append(tokenCppStringSimpleQuote, "'\\?.'");
|
||||||
m_lexer.appendSection(tokenCppSectionBrace, "\\{", "\\}");
|
m_lexer.append(tokenCppBraceIn, "\\{");
|
||||||
m_lexer.appendSection(tokenCppSectionPthese, "\\(", "\\)");
|
m_lexer.append(tokenCppBraceOut, "\\}");
|
||||||
m_lexer.appendSection(tokenCppSectionHook, "\\[", "\\]");
|
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(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(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");
|
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(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(tokenCppBoolean, "\\b(true|false)\\b");
|
||||||
m_lexer.append(tokenCppCondition, "==|>=|<=|!=|<|>|&&|\\|\\|");
|
m_lexer.append(tokenCppCondition, "==|>=|<=|!=|<|>|&&|\\|\\|");
|
||||||
m_lexer.append(tokenCppAssignation, "(=|\\*|/|-|+|&)");
|
m_lexer.append(tokenCppAssignation, "(\\+=|-=|\\*=|/=|=|\\*|/|--|-|\\+\\+|\\+|&)");
|
||||||
m_lexer.append(tokenCppString, "\\w+");
|
m_lexer.append(tokenCppString, "\\w+");
|
||||||
m_lexer.append(tokenCppSeparator, "(;|,|::|:)");
|
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() {
|
eci::ParserCpp::~ParserCpp() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void printNode(const std::string& _data, const std::vector<std::shared_ptr<eci::LexerNode>>& _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<eci::LexerNodeContainer> sec = std::dynamic_pointer_cast<eci::LexerNodeContainer>(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='" <<std::string(_data, it->getStartPos(), it->getStopPos()-it->getStartPos()) << "'" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool eci::ParserCpp::parse(const std::string& _data) {
|
bool eci::ParserCpp::parse(const std::string& _data) {
|
||||||
m_result = m_lexer.interprete(_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) {
|
for (auto &it : m_result.m_list) {
|
||||||
ECI_INFO(" start=" << it->getStartPos() << " stop=" << it->getStopPos() << " data='" <<std::string(_data, it->getStartPos(), it->getStopPos()-it->getStartPos()) << "'" );
|
ECI_INFO(" start=" << it->getStartPos() << " stop=" << it->getStopPos() << " data='" <<std::string(_data, it->getStartPos(), it->getStopPos()-it->getStartPos()) << "'" );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,52 @@
|
|||||||
#include <eci/Lexer.h>
|
#include <eci/Lexer.h>
|
||||||
|
|
||||||
namespace eci {
|
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 {
|
class ParserCpp {
|
||||||
private:
|
public:
|
||||||
eci::Lexer m_lexer;
|
eci::Lexer m_lexer;
|
||||||
eci::LexerResult m_result;
|
eci::LexerResult m_result;
|
||||||
public:
|
public:
|
||||||
|
23
eci/visibility.h
Normal file
23
eci/visibility.h
Normal file
@ -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 <etk/types.h>
|
||||||
|
|
||||||
|
namespace eci {
|
||||||
|
enum visibility {
|
||||||
|
visibilityNone,
|
||||||
|
visibilityPrivate,
|
||||||
|
visibilityProtected,
|
||||||
|
visibilityPublic,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -17,6 +17,15 @@ def create(target):
|
|||||||
'eci/eci.cpp',
|
'eci/eci.cpp',
|
||||||
'eci/Lexer.cpp',
|
'eci/Lexer.cpp',
|
||||||
'eci/debug.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'
|
'eci/lang/ParserCpp.cpp'
|
||||||
])
|
])
|
||||||
myModule.add_export_path(tools.get_current_path(__file__))
|
myModule.add_export_path(tools.get_current_path(__file__))
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
printf("Hello\n");
|
printf("Hello 1\n");
|
||||||
printf("Hello\n"); /* this is a comment */ printf("Hello\n");
|
printf("Hello 2\n"); /* this is a comment */ printf("Hello 3\n");
|
||||||
printf("Hello\n");
|
printf("Hello 4\n");
|
||||||
// this is also a comment sayhello();
|
// this is also a comment sayhello();
|
||||||
printf("Hello\n");
|
printf("Hello 5\n");
|
||||||
printf("Hello\n"); /* this is a second comment */ printf("Hello\n");
|
printf("Hello 6\n"); /* this is a second comment */ printf("Hello 7\n");
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
void main() {}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
Hello
|
Hello 1
|
||||||
Hello
|
Hello 2
|
||||||
Hello
|
Hello 3
|
||||||
Hello
|
Hello 4
|
||||||
Hello
|
Hello 5
|
||||||
|
Hello 6
|
||||||
|
Hello 7
|
||||||
|
12
tests/55_section.c
Normal file
12
tests/55_section.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
//#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user