Skip to content
Snippets Groups Projects
Commit 7f5e6688 authored by Maxence Naud's avatar Maxence Naud
Browse files

Fix Parser destructors inline error and remove 'using namespace' from cpp files

parent dd21faee
No related branches found
No related tags found
1 merge request!54horizontal tiling
...@@ -12,15 +12,17 @@ namespace Aidge{ ...@@ -12,15 +12,17 @@ namespace Aidge{
/** /**
* @brief this class uses the lexer to create an AST according to a set of gramer rules * @brief this class uses the lexer to create an AST according to a set of gramer rules
*/ */
class GraphParser{ class GraphParser {
public: public:
/** /**
* @brief AST graph creation function * @brief AST graph creation function
* @param gRegexExpressions String representing the logical fuction to be performed * @param gRegexExpressions String representing the logical fuction to be performed
*/ */
GraphParser(const std::string gRegexExpressions); GraphParser(const std::string gRegexExpressions);
~GraphParser() noexcept;
/** /**
* @brief AST graph creation function * @brief AST graph creation function
* @return The AST tree * @return The AST tree
...@@ -35,7 +37,7 @@ class GraphParser{ ...@@ -35,7 +37,7 @@ class GraphParser{
const std::string getQuery(); const std::string getQuery();
private: private:
/** /**
* @brief restart at the start of the ConditionalExpressions for LEXER and restart mCurrentToken * @brief restart at the start of the ConditionalExpressions for LEXER and restart mCurrentToken
*/ */
......
...@@ -29,7 +29,7 @@ using ASTNodeCh = std::vector<std::shared_ptr<AstNode<ConditionalTokenTypes>>>; ...@@ -29,7 +29,7 @@ using ASTNodeCh = std::vector<std::shared_ptr<AstNode<ConditionalTokenTypes>>>;
/** /**
* @brief this class uses the lexer to create an AST according to a set of gramer rules * @brief this class uses the lexer to create an AST according to a set of gramer rules
*/ */
class ConditionalParser{ class ConditionalParser {
public: public:
/** /**
...@@ -38,6 +38,8 @@ class ConditionalParser{ ...@@ -38,6 +38,8 @@ class ConditionalParser{
*/ */
ConditionalParser(const std::string ConditionalExpressions); ConditionalParser(const std::string ConditionalExpressions);
~ConditionalParser() noexcept;
/** /**
* @brief AST graph creation function * @brief AST graph creation function
* @return The AST tree * @return The AST tree
......
#include "aidge/graphRegex/GraphParser.hpp" #include <memory>
#include <string>
#include <vector>
using namespace Aidge; #include "aidge/graphRegex/GraphParser.hpp"
GraphParser::GraphParser(const std::string gRegexExpressions): Aidge::GraphParser::GraphParser(const std::string gRegexExpressions):
mLexer(gRegexExpressions) mLexer(gRegexExpressions)
{ {
mCurrentToken = mLexer.getNextToken(); mCurrentToken = mLexer.getNextToken();
} }
Aidge::GraphParser::~GraphParser() noexcept = default;
const std::string GraphParser::getQuery(){
const std::string Aidge::GraphParser::getQuery(){
return mLexer.getQuery(); return mLexer.getQuery();
} }
std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::parse(void){ std::shared_ptr<Aidge::AstNode<Aidge::gRegexTokenTypes>> Aidge::GraphParser::parse(void){
std::shared_ptr<AstNode<gRegexTokenTypes>> astTree = constructAstAllExpr(); std::shared_ptr<AstNode<gRegexTokenTypes>> astTree = constructAstAllExpr();
rstParser(); rstParser();
...@@ -21,14 +25,14 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::parse(void){ ...@@ -21,14 +25,14 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::parse(void){
} }
void GraphParser::rstParser(void){ void Aidge::GraphParser::rstParser(void){
mLexer.rstPosition(); mLexer.rstPosition();
mCurrentToken = mLexer.getNextToken(); mCurrentToken = mLexer.getNextToken();
} }
void GraphParser::ackToken(gRegexTokenTypes tokenType){ void Aidge::GraphParser::ackToken(gRegexTokenTypes tokenType){
if(mCurrentToken->getType() == tokenType ){ if(mCurrentToken->getType() == tokenType ){
try { try {
mCurrentToken = mLexer.getNextToken(); mCurrentToken = mLexer.getNextToken();
...@@ -48,7 +52,7 @@ void GraphParser::ackToken(gRegexTokenTypes tokenType){ ...@@ -48,7 +52,7 @@ void GraphParser::ackToken(gRegexTokenTypes tokenType){
/* /*
exp : KEY(QOM | QZM)? | CKEY | domain exp : KEY(QOM | QZM)? | CKEY | domain
*/ */
std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstExp(void) std::shared_ptr<Aidge::AstNode<Aidge::gRegexTokenTypes>> Aidge::GraphParser::constructAstExp(void)
{ {
try{ try{
...@@ -86,15 +90,15 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstExp(void) ...@@ -86,15 +90,15 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstExp(void)
} }
/* /*
seq :exp (NEXT seq)* seq :exp (NEXT seq)*
*/ */
std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstSeq(void) std::shared_ptr<Aidge::AstNode<Aidge::gRegexTokenTypes>> Aidge::GraphParser::constructAstSeq(void)
{ {
try{ try{
std::shared_ptr<AstNode<gRegexTokenTypes>> left = constructAstExp(); std::shared_ptr<AstNode<gRegexTokenTypes>> left = constructAstExp();
if(mCurrentToken->getType() == gRegexTokenTypes::NEXT ) if(mCurrentToken->getType() == gRegexTokenTypes::NEXT )
{ {
std::shared_ptr<ParsingToken<gRegexTokenTypes>> token = mCurrentToken->copy(); std::shared_ptr<ParsingToken<gRegexTokenTypes>> token = mCurrentToken->copy();
ackToken(gRegexTokenTypes::NEXT); ackToken(gRegexTokenTypes::NEXT);
...@@ -114,15 +118,15 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstSeq(void) ...@@ -114,15 +118,15 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstSeq(void)
/* /*
LPAREN seq RPAREN (QOM | QZM) LPAREN seq RPAREN (QOM | QZM)
*/ */
std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstDomain(void) std::shared_ptr<Aidge::AstNode<Aidge::gRegexTokenTypes>> Aidge::GraphParser::constructAstDomain(void)
{ {
try{ try{
std::shared_ptr<ParsingToken<gRegexTokenTypes>> token ; std::shared_ptr<ParsingToken<gRegexTokenTypes>> token ;
std::shared_ptr<AstNode<gRegexTokenTypes>> node ; std::shared_ptr<AstNode<gRegexTokenTypes>> node ;
token = mCurrentToken->copy(); token = mCurrentToken->copy();
ackToken(gRegexTokenTypes::LPAREN); ackToken(gRegexTokenTypes::LPAREN);
node = std::make_shared<AstNode<gRegexTokenTypes>>(token, node = std::make_shared<AstNode<gRegexTokenTypes>>(token,
...@@ -144,7 +148,7 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstDomain(void) ...@@ -144,7 +148,7 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstDomain(void)
errorMessage << "Bad syntax constructAstDomain must have quantifier \n"; errorMessage << "Bad syntax constructAstDomain must have quantifier \n";
throw std::runtime_error(errorMessage.str()); throw std::runtime_error(errorMessage.str());
} }
return node; return node;
} catch (const std::runtime_error& e) { } catch (const std::runtime_error& e) {
...@@ -157,12 +161,12 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstDomain(void) ...@@ -157,12 +161,12 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstDomain(void)
/* /*
allExpr: seq (SEP allExpr)* | STOP allExpr: seq (SEP allExpr)* | STOP
*/ */
std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstAllExpr(void) std::shared_ptr<Aidge::AstNode<Aidge::gRegexTokenTypes>> Aidge::GraphParser::constructAstAllExpr(void)
{ {
try{ try{
std::shared_ptr<AstNode<gRegexTokenTypes>> left = constructAstSeq(); std::shared_ptr<AstNode<gRegexTokenTypes>> left = constructAstSeq();
if(mCurrentToken->getType() == gRegexTokenTypes::SEP ) if(mCurrentToken->getType() == gRegexTokenTypes::SEP )
{ {
std::shared_ptr<ParsingToken<gRegexTokenTypes>> token = mCurrentToken->copy(); std::shared_ptr<ParsingToken<gRegexTokenTypes>> token = mCurrentToken->copy();
ackToken(gRegexTokenTypes::SEP); ackToken(gRegexTokenTypes::SEP);
...@@ -170,7 +174,7 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstAllExpr(void ...@@ -170,7 +174,7 @@ std::shared_ptr<AstNode<gRegexTokenTypes>> GraphParser::constructAstAllExpr(void
if(mCurrentToken->getType() == gRegexTokenTypes::STOP ) if(mCurrentToken->getType() == gRegexTokenTypes::STOP )
{ {
return left; return left;
} }
std::shared_ptr<AstNode<gRegexTokenTypes>> newNode = std::make_shared<AstNode<gRegexTokenTypes>>(token, std::shared_ptr<AstNode<gRegexTokenTypes>> newNode = std::make_shared<AstNode<gRegexTokenTypes>>(token,
std::vector<std::shared_ptr<AstNode<gRegexTokenTypes>>>{left,constructAstAllExpr()}); std::vector<std::shared_ptr<AstNode<gRegexTokenTypes>>>{left,constructAstAllExpr()});
left = newNode; left = newNode;
......
#include <memory>
#include <vector>
#include "aidge/nodeTester/ConditionalParser.hpp" #include "aidge/nodeTester/ConditionalParser.hpp"
using namespace Aidge;
////////////////////////////// //////////////////////////////
//ConditionalParser //ConditionalParser
////////////////////////////// //////////////////////////////
ConditionalParser::ConditionalParser(const std::string ConditionalExpressions):mLexer(ConditionalExpressions){ Aidge::ConditionalParser::ConditionalParser(const std::string ConditionalExpressions)
: mLexer(ConditionalExpressions)
{
mCurrentToken = mLexer.getNextToken(); mCurrentToken = mLexer.getNextToken();
} }
void ConditionalParser::rstParser(void){ Aidge::ConditionalParser::~ConditionalParser() noexcept = default;
void Aidge::ConditionalParser::rstParser(void){
mLexer.rstPosition(); mLexer.rstPosition();
mCurrentToken = mLexer.getNextToken(); mCurrentToken = mLexer.getNextToken();
} }
void ConditionalParser::ackToken(ConditionalTokenTypes tokenType){ void Aidge::ConditionalParser::ackToken(ConditionalTokenTypes tokenType){
if(mCurrentToken->getType() == tokenType ){ if(mCurrentToken->getType() == tokenType ){
try { try {
...@@ -38,7 +42,7 @@ void ConditionalParser::ackToken(ConditionalTokenTypes tokenType){ ...@@ -38,7 +42,7 @@ void ConditionalParser::ackToken(ConditionalTokenTypes tokenType){
std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstVal(void){ std::shared_ptr<Aidge::AstNode<Aidge::ConditionalTokenTypes>> Aidge::ConditionalParser::constructAstVal(void){
/* /*
val : (KEY|INTEGER|FOAT|STRING|LAMBDA) val : (KEY|INTEGER|FOAT|STRING|LAMBDA)
*/ */
...@@ -76,7 +80,7 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstV ...@@ -76,7 +80,7 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstV
} }
std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstLambda(void){ std::shared_ptr<Aidge::AstNode<Aidge::ConditionalTokenTypes>> Aidge::ConditionalParser::constructAstLambda(void){
/* /*
AstLambda : LAMBDA val (ARGSEP val)* RPAREN AstLambda : LAMBDA val (ARGSEP val)* RPAREN
*/ */
...@@ -94,7 +98,7 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstL ...@@ -94,7 +98,7 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstL
return std::make_shared<AstNode<ConditionalTokenTypes>>(tokenLdb,paramLambda); return std::make_shared<AstNode<ConditionalTokenTypes>>(tokenLdb,paramLambda);
} }
std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstCmpr(void){ std::shared_ptr<Aidge::AstNode<Aidge::ConditionalTokenTypes>> Aidge::ConditionalParser::constructAstCmpr(void){
/* /*
cmpr : val (EQ|NEQ) val | LPAREN expr RPAREN cmpr : val (EQ|NEQ) val | LPAREN expr RPAREN
NOT ir ? NOT ir ?
...@@ -125,7 +129,7 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstC ...@@ -125,7 +129,7 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstC
} }
} }
std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstExpr(std::size_t precLimit /*= 0*/){ std::shared_ptr<Aidge::AstNode<Aidge::ConditionalTokenTypes>> Aidge::ConditionalParser::constructAstExpr(std::size_t precLimit /*= 0*/){
/* /*
expr : cmpr ((AND | OR) cmpr)* expr : cmpr ((AND | OR) cmpr)*
the NOT is not binary OP can be use in pratt the NOT is not binary OP can be use in pratt
...@@ -134,27 +138,27 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstE ...@@ -134,27 +138,27 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstE
OR OR
*/ */
//the not //the not
std::shared_ptr<AstNode<ConditionalTokenTypes>> left; std::shared_ptr<AstNode<ConditionalTokenTypes>> left;
std::shared_ptr<ParsingToken<ConditionalTokenTypes>> token = mCurrentToken->copy(); std::shared_ptr<ParsingToken<ConditionalTokenTypes>> token = mCurrentToken->copy();
if (mCurrentToken->getType() == ConditionalTokenTypes::NOT ){ if (mCurrentToken->getType() == ConditionalTokenTypes::NOT ){
ackToken(ConditionalTokenTypes::NOT ); ackToken(ConditionalTokenTypes::NOT );
left= std::make_shared<AstNode<ConditionalTokenTypes>>(token,ASTNodeCh{constructAstCmpr()}); left= std::make_shared<AstNode<ConditionalTokenTypes>>(token,ASTNodeCh{constructAstCmpr()});
}else{ }else{
left= constructAstCmpr(); left= constructAstCmpr();
} }
//pratt //pratt
while (mCurrentToken->getType() != ConditionalTokenTypes::STOP ) //security while (mCurrentToken->getType() != ConditionalTokenTypes::STOP ) //security
{ {
token = mCurrentToken->copy(); token = mCurrentToken->copy();
//if the token is not in the map is not a operator so we consider a prec of 0 //if the token is not in the map is not a operator so we consider a prec of 0
if (ConditionalPrec.find(token->getType()) ==ConditionalPrec.end() ){ if (ConditionalPrec.find(token->getType()) ==ConditionalPrec.end() ){
return left; return left;
} }
//if my actual operator have a prec <= of the last operator //if my actual operator have a prec <= of the last operator
std::size_t prec = ConditionalPrec.at(token->getType()); std::size_t prec = ConditionalPrec.at(token->getType());
if (prec <= precLimit){ if (prec <= precLimit){
return left; return left;
...@@ -165,7 +169,7 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstE ...@@ -165,7 +169,7 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstE
std::shared_ptr<AstNode<ConditionalTokenTypes>> right = constructAstExpr(prec); std::shared_ptr<AstNode<ConditionalTokenTypes>> right = constructAstExpr(prec);
//i'm not sur what append to newNode //i'm not sur what append to newNode
//std::shared_ptr<AstNode<ConditionalTokenTypes>> newNode = std::make_shared<AstNode<ConditionalTokenTypes>>(token,ASTNodeCh{left,constructAstCmpr()}); //std::shared_ptr<AstNode<ConditionalTokenTypes>> newNode = std::make_shared<AstNode<ConditionalTokenTypes>>(token,ASTNodeCh{left,constructAstCmpr()});
std::shared_ptr<AstNode<ConditionalTokenTypes>> newNode = std::make_shared<AstNode<ConditionalTokenTypes>>(token,ASTNodeCh{left,right}); std::shared_ptr<AstNode<ConditionalTokenTypes>> newNode = std::make_shared<AstNode<ConditionalTokenTypes>>(token,ASTNodeCh{left,right});
left = newNode; left = newNode;
...@@ -174,10 +178,10 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstE ...@@ -174,10 +178,10 @@ std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::constructAstE
} }
std::shared_ptr<AstNode<ConditionalTokenTypes>> ConditionalParser::parse(void){ std::shared_ptr<Aidge::AstNode<Aidge::ConditionalTokenTypes>> Aidge::ConditionalParser::parse(void){
/* /*
expr : cmpr ((AND | OR) cmpr)* expr : cmpr ((AND | OR) cmpr)*
cmpr : val (EQ|NEQ) val | LPAREN expr RPAREN | BOOL | LAMBDA cmpr : val (EQ|NEQ) val | LPAREN expr RPAREN | BOOL | LAMBDA
val : (KEY|INTEGER|FOAT|STRING|LAMBDA) val : (KEY|INTEGER|FOAT|STRING|LAMBDA)
lambda : LAMBDA val (ARGSEP val)* RPAREN lambda : LAMBDA val (ARGSEP val)* RPAREN
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment