Commit e7a8eb92 authored by BenRejeb Iyed's avatar BenRejeb Iyed

final fixes

parent a744141d
......@@ -61,6 +61,9 @@ class RecognizerPointer;
class Recognizer : public std::enable_shared_from_this<Recognizer>{
public:
void setName(const std::string &name);
void setOnlyName(const std::string& name);
void setId(int Id);
const std::string &getName()const;
BELR_PUBLIC size_t feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
unsigned int getId()const{
......@@ -75,9 +78,8 @@ public:
virtual void save(std::ofstream& fichier, long &savePos)=0;
virtual bool equal(const std::shared_ptr<Recognizer> &CR)=0;
virtual void linkPointer(std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd)=0;
virtual bool operator==(Recognizer &CR)=0;
//DEBUG FUNCTION
virtual void printtype()=0;
protected:
Recognizer() = default;
......@@ -95,11 +97,8 @@ public:
void save(std::ofstream& fichier, long &savePos);
bool equal(const std::shared_ptr<Recognizer> &CR);
static std::shared_ptr<CharRecognizer> loadVect(std::vector<std::string>::const_iterator &inIter);
//DEBUG FUNCTION
void printtype();
void linkPointer(std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
private:
bool operator==(Recognizer &CR);
virtual void _optimize(int recursionLevel);
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
int mToRecognize;
......@@ -112,10 +111,9 @@ public:
std::shared_ptr<Selector> addRecognizer(const std::shared_ptr<Recognizer> &element);
void save(std::ofstream& fichier, long &savePos);
bool equal(const std::shared_ptr<Recognizer> &SEL);
static std::shared_ptr<Selector> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterEnd);
//DEBUG FUNCTION
void printtype();
static std::shared_ptr<Selector> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
void linkPointer(std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool operator==(Recognizer &CR);
......@@ -133,11 +131,10 @@ class ExclusiveSelector : public Selector{
public:
ExclusiveSelector();
void save(std::ofstream& fichier, long &savePos);
static std::shared_ptr<ExclusiveSelector> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterEnd);
bool equal(const std::shared_ptr<Recognizer> &CR); //MODIFIE PAR IYED
//DEBUG FUNCTION
void printtype();
static std::shared_ptr<ExclusiveSelector> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool equal(const std::shared_ptr<Recognizer> &CR);
void linkPointer(std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool operator==(Recognizer &SEQ);
private:
......@@ -148,12 +145,11 @@ class Sequence : public Recognizer{
public:
std::shared_ptr<Sequence> addRecognizer(const std::shared_ptr<Recognizer> &element);
virtual bool _getTransitionMap(TransitionMap *mask);
void save(std::ofstream& fichier, long &savePos); //MODIFIE PAR IYED
static std::shared_ptr<Sequence> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterEnd);
bool equal(const std::shared_ptr<Recognizer> &CR); //MODIFIE PAR IYED
//DEBUG FUNCTION
void printtype();
void save(std::ofstream& fichier, long &savePos);
static std::shared_ptr<Sequence> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool equal(const std::shared_ptr<Recognizer> &CR);
void linkPointer(std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool operator==(Recognizer &SEQ);
protected:
......@@ -169,11 +165,9 @@ public:
virtual bool _getTransitionMap(TransitionMap *mask);
void save(std::ofstream& fichier, long &savePos); //MODIFIE PAR IYED
bool equal(const std::shared_ptr<Recognizer> &CR); //MODIFIE PAR IYED
static std::shared_ptr<Loop> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterEnd);
//DEBUG FUNCTION
void printtype();
static std::shared_ptr<Loop> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
void linkPointer(std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool operator==(Recognizer &SEQ);
......@@ -199,12 +193,11 @@ public:
class CharRange : public Recognizer{
public:
CharRange(int begin, int end);
void save(std::ofstream& fichier, long &savePos); //MODIFIE PAR IYED
void save(std::ofstream& fichier, long &savePos);
static std::shared_ptr<CharRange> loadVect(std::vector<std::string>::const_iterator &inIter);
bool equal(const std::shared_ptr<Recognizer> &CR); //MODIFIE PAR IYED
//DEBUG FUNCTION
void printtype();
bool equal(const std::shared_ptr<Recognizer> &CR);
void linkPointer(std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool operator==(Recognizer &SEQ);
......@@ -218,12 +211,11 @@ class Literal : public Recognizer{
public:
Literal(const std::string &lit);
virtual bool _getTransitionMap(TransitionMap *mask);
void save(std::ofstream& fichier, long &savePos); //MODIFIE PAR IYED
void save(std::ofstream& fichier, long &savePos);
static std::shared_ptr<Literal> loadVect(std::vector<std::string>::const_iterator &inIter);
bool equal(const std::shared_ptr<Recognizer> &CR); //MODIFIE PAR IYED
//DEBUG FUNCTION
void printtype();
bool equal(const std::shared_ptr<Recognizer> &CR);
void linkPointer(std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool operator==(Recognizer &SEQ);
private:
......@@ -244,12 +236,11 @@ public:
RecognizerPointer();
std::shared_ptr<Recognizer> getPointed();
void setPointed(const std::shared_ptr<Recognizer> &r);
void save(std::ofstream& fichier, long &savePos); //MODIFIE PAR IYED
static std::shared_ptr<RecognizerPointer> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<Recognizer>>::iterator &rcptrIterEnd);
bool equal(const std::shared_ptr<Recognizer> &CR); //MODIFIE PAR IYED
//DEBUG FUNCTION
void printtype();
void save(std::ofstream& fichier, long &savePos);
static std::shared_ptr<RecognizerPointer> loadVect(std::vector<std::string>::const_iterator &inIter, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool equal(const std::shared_ptr<Recognizer> &CR);
void linkPointer(std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterBegin, std::list<std::shared_ptr<RecognizerPointer>>::iterator &rcptrIterEnd);
bool operator==(Recognizer &SEQ);
private:
virtual void _optimize(int recursionLevel);
......@@ -339,8 +330,7 @@ public:
BELR_PUBLIC static std::shared_ptr<Grammar> loadVectRulesMap(std::string fileName);
//comare functions
bool equal(std::shared_ptr<Grammar> &gramCompared);
//debug functions
void debugGrammar();
private:
void assignRule(const std::string &name, const std::shared_ptr<Recognizer> &rule);
......
......@@ -1454,8 +1454,9 @@ bool Grammar::equal(shared_ptr<Grammar> &gramCompared){
it = mRules.begin();
while (it != mRules.end()/* && condition*/){
if(it->first == itComp->first){
if(!(it->second == itComp->second)){
if(!(*(it->second) == *(itComp->second))){
condition = false;
cout << "MERDE" << endl;
}
}
else{
......@@ -1472,7 +1473,7 @@ bool Grammar::equal(shared_ptr<Grammar> &gramCompared){
string firstRule = (*itRcp)->getName();
string secondRule = (*itRcpComp)->getName();
if (!firstRule.compare(secondRule)){
if (!((*itRcp)->getPointed() == (*itRcpComp)->getPointed())){
if (!(*(*itRcp)->getPointed() == *(*itRcpComp)->getPointed())){
condition = false;
}
}
......
......@@ -26,7 +26,7 @@ else()
set(BELR_LIBRARIES_FOR_TOOLS belr-static)
endif()
foreach(EXECTUABLE belr-parse RecognizerPointerVectorized-test GrammarDumpParse-test SelectorVectorized-test SequenceVectorized-test LoopVectorized-test ExclusiveSelectorVectorized-test LiteralVectorized-test CharRangeVectorized-test GrammarDump-test )
foreach(EXECTUABLE belr-parse GrammarDumpParse-test GrammarDump-test )
set(SOURCE_FILES_CXX ${EXECTUABLE}.cc)
bc_apply_compile_flags(SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
add_executable(${EXECTUABLE} ${SOURCE_FILES_CXX})
......
#include "belr/grammarbuilder.h"
#include "belr/abnf.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <chrono>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <memory>
//#include <chrono>
using namespace belr;
using namespace std;
long savePosition = 0;
long loadPosition = 0;
template<typename Out>
void split(const std::string &s, char delim, Out result) {
std::stringstream ss;
ss.str(s);
std::string item;
while (std::getline(ss, item, delim)) {
*(result++) = item;
}
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, std::back_inserter(elems));
return elems;
}
int main(int argc, char *argv[]){
//Create two charrecognizers
const shared_ptr<CharRange> stringBasic = dynamic_pointer_cast<CharRange>(Utils::char_range(97, 100));
cout << "*********FEEDING THE ORIGINAL RECOGNIZERS*********" << endl;
//verification avec feed
if ((stringBasic->feed(NULL, "a", 0) == 1) && (stringBasic->feed(NULL, "b", 0) == 1) && (stringBasic->feed(NULL, "c", 0) == 1) && (stringBasic->feed(NULL, "d", 0) == 1)) cout << "SUCESS : CharRange feed successfull" << endl;
else cout << "FAILED : CharRange feed gone wrong" << endl;
//SAVE AND LOAD
ofstream ofichier ("test-char_range.bin", ios::out | ios::app);
stringBasic->save(ofichier, savePosition);
ofichier.close();
ifstream ifichier("test-char_range.bin", ios::in);
string contenu; // déclaration d'une chaîne qui contiendra la ligne lue
getline(ifichier, contenu); // on met dans "contenu" la ligne
std::vector<std::string> result = split(contenu, ' ');
vector<string>::const_iterator i = result.begin();
const shared_ptr<CharRange> stringBasicLoaded = CharRange::loadVect(i);
ifichier.close();
//verification du save and mload
cout << "*********VERIFIYING IF RECOGNIZERS MATCH*********" << endl;
if(*stringBasic.get() == *stringBasicLoaded.get()) cout << "SUCESS : CharRange matches loaded" << endl;
else cout << "FAILED : CharRange doesnt match loaded" << endl;
cout << "*********FEEDING THE LOADED RECOGNIZERS*********" << endl;
if ((stringBasicLoaded->feed(NULL, "a",0) == 1) && (stringBasicLoaded->feed(NULL, "b",0) == 1) && (stringBasicLoaded->feed(NULL, "c",0) == 1) && (stringBasicLoaded->feed(NULL, "d",0) == 1)){
cout << "SUCESS : loaded charrange feed successfull" << endl;
}
else{
cout << "FAILED : loaded charrange feed gone wrong" << endl;
}
}
#include "belr/grammarbuilder.h"
#include "belr/abnf.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <chrono>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <memory>
//#include <chrono>
#include <fstream>
#include <string>
using namespace belr;
using namespace std;
long savePosition = 0;
long loadPosition = 0;
template<typename Out>
void split(const std::string &s, char delim, Out result) {
std::stringstream ss;
ss.str(s);
std::string item;
while (std::getline(ss, item, delim)) {
*(result++) = item;
}
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, std::back_inserter(elems));
return elems;
}
int main(int argc, char *argv[]){
//Create two charrecognizers
shared_ptr<CharRecognizer> character = Foundation::charRecognizer('b', false);
shared_ptr<CharRecognizer> character2 = Foundation::charRecognizer('a', false);
cout << "*********FEEDING THE ORIGINAL RECOGNIZERS*********" << endl;
//verification avec feed
if (character->feed(NULL, "b", 0) == 1) cout << "SUCESS : first feed successfull" << endl;
else cout << "FAILED : first feed gone wrong" << endl;
if (character2->feed(NULL, "a", 0) == 1) cout << "SUCESS : second feed successfull" << endl;
else cout << "FAILED : second feed gone wrong" << endl;
remove("test-char.bin");
//SAVE AND LOAD
ofstream ofichier ("test-char.bin", ios::out | ios::app | ios::binary);
character->save(ofichier, savePosition);
character2->save(ofichier, savePosition);
ofichier.close();
ifstream ifichier ("test-char.bin", ios::in | ios::binary);
string contenu; // déclaration d'une chaîne qui contiendra la ligne lue
getline(ifichier, contenu); // on met dans "contenu" la ligne
std::vector<std::string> result = split(contenu, ' ');
vector<string>::const_iterator i = result.begin();
const shared_ptr<CharRecognizer> characterLoaded = CharRecognizer::loadVect(i);
const shared_ptr<CharRecognizer> characterLoaded2 = CharRecognizer::loadVect(i);
ifichier.close();
cout << "*********VERIFIYING IF RECOGNIZERS MATCH*********" << endl;
if(character == characterLoaded) cout << "SUCESS : first character matches loaded" << endl;
else cout << "FAILED : first character doesnt match loaded" << endl;
if(character2 == characterLoaded2) cout << "SUCESS : second character matches loaded" << endl;
else cout << "FAILED : second character doesnt match loaded" << endl;
cout << "*********FEEDING THE LOADED RECOGNIZERS*********" << endl;
if (characterLoaded->feed(NULL, "b",0)) cout << "SUCESS : first loaded character feed successfull" << endl;
else cout << "FAILED : first loaded character feed gone wrong" << endl;
if (characterLoaded2->feed(NULL, "a",0)) cout << "SUCESS : second loaded character feed successfull" << endl;
else cout << "FAILED : second loaded character feed gone wrong" << endl;
}
This diff is collapsed.
#include "belr/grammarbuilder.h"
#include "belr/abnf.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <chrono>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <memory>
//#include <chrono>
using namespace belr;
using namespace std;
long savePosition = 0;
long loadPosition = 0;
template<typename Out>
void split(const std::string &s, char delim, Out result) {
std::stringstream ss;
ss.str(s);
std::string item;
while (std::getline(ss, item, delim)) {
*(result++) = item;
}
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, std::back_inserter(elems));
return elems;
}
int main(int argc, char *argv[]){
const shared_ptr<Literal> chaine = dynamic_pointer_cast<Literal>(Utils::literal("abcd"));
cout << "*********FEEDING THE ORIGINAL RECOGNIZERS*********" << endl;
//verification avec feed
if (chaine->feed(NULL, "abcd", 0) == 4) {
cout << "SUCESS : Literal feed successfull" << endl;
}
else{
cout << "FAILED : Literal feed gone wrong" << endl;
}
remove("test-lit.bin");
//SAVE AND LOAD
ofstream ofichier ("test-lit.bin", ios::out | ios::app);
chaine->save(ofichier ,savePosition);
ofichier.close();
ifstream ifichier ("test-lit.bin", ios::in);
string contenu; // déclaration d'une chaîne qui contiendra la ligne lue
getline(ifichier, contenu); // on met dans "contenu" la ligne
std::vector<std::string> result = split(contenu, ' ');
vector<string>::const_iterator i = result.begin();
const shared_ptr<Literal> chaine_loaded = Literal::loadVect(i);
ifichier.close();
//verification du save and mload
cout << "*********VERIFIYING IF RECOGNIZERS MATCH*********" << endl;
if(*chaine.get() == *chaine_loaded.get()){
cout << "SUCESS : Literal matches loaded" << endl;
}
else{
cout << "FAILED : Literal doesnt match loaded" << endl;
}
cout << "*********FEEDING THE LOADED RECOGNIZERS*********" << endl;
if (chaine_loaded->feed(NULL, "abcd",0) == 4){
cout << "SUCESS : Loaded Literal feed successfull" << endl;
}
else{
cout << "FAILED : Loaded Literal feed gone wrong" << endl;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "belr/grammarbuilder.hh"
#include "belr/abnf.hh"
#include <iostream>
#include <fstream>
#include <sstream>
#include <chrono>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <memory>
using namespace belr;
using namespace std;
int main(int argc, char *argv[]){
// WHAT IS PARSER CONTEXT BASER : objet necessaire pour l'utilisation de feed
// WHAT IS STRING input : string a comparer (partant du principe que )
// WHAT IS pos : position du caractère (je sais pas ou maybe dans la grammaire ? maybe dans le fichier de test ? )
shared_ptr<CharRecognizer> caractere = Foundation::charRecognizer('a', false);
shared_ptr<CharRecognizer> caractere2 = Foundation::charRecognizer('b', false);
if (caractere->feed(NULL, "a", 0) == 1) {
cout << "first success" << endl;
}
else{
cout << "fail" << endl;
}
if (caractere2->feed(NULL, "b", 0) == 1) {
cout << "first success" << endl;
}
else{
cout << "fail" << endl;
}
//waaht is feed ?
//no viable conversion from 'belr::CharRecognizer' to 'const std::shared_ptr<CharRecognizer>'
//SAVE AND LOAD
caractere->Save("test.txt");
shared_ptr<CharRecognizer> caractere_loaded = caractere->Load("test.txt");
caractere2->Save("test.txt");
shared_ptr<CharRecognizer> caractere2_loaded = caractere->Load("test.txt");
if(caractere->equal(caractere_loaded)){
cout << "second success" << endl;
}
else{
cout << "fail" << endl;
}
if (caractere_loaded->feed(NULL, "a",0)){
cout << "third success" << endl;
}
else{
cout << "fail" << endl;
}
if(caractere2->equal(caractere2_loaded)){
cout << "second success" << endl;
}
else{
cout << "fail" << endl;
}
if (caractere2_loaded->feed(NULL, "b",0)){
cout << "third success" << endl;
}
else{
cout << "fail" << endl;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment