Commit f04ae6a8 authored by Pascal Noisette's avatar Pascal Noisette
Browse files

commit de Arthur & Pascal...mise en oeuvre d'un automate de reconnaissance de la trace performant

parent 53753f37
......@@ -19,6 +19,15 @@ Line::Line(const char* filename){
source.open(filename);
_eof = false;
}
void Line::print()
{
std::cout << "-" ;
for(int i=0;i<_tokens.size();i++)
std::cout << _tokens[i] << " " ;
std::cout << "-" <<endl ;
}
Line::~Line(){}
......@@ -28,7 +37,7 @@ bool Line::starts_with(const std::string & s) const{
/*
bool Line::operator== (Line &l){
int size_of_this_line = length();
......@@ -43,9 +52,16 @@ bool Line::operator== (Line &l){
else
return false;
}
*/
std::string &Line::item (int i){
return _tokens[i];
bool Line::item (int i,std::string &e){
if (i>=_tokens.size())
return false;
e = _tokens[i];
return true;
}
......@@ -63,14 +79,19 @@ bool Line::eof(){
return _eof;
}
void Line::newline(){
clear();
char * tok;
std::string str;
while ((tok=source.lire_token())!=NULL){
str.assign(tok);
_tokens.push_back(str);
if (str == "\n")
return;
_tokens.push_back(str);
}
_eof=true;
......
......@@ -63,9 +63,9 @@ public:
* \brief the ith token in the line
*
*/
std::string& item (int i);
bool item (int i,std::string &e);
void print();
/*!
......
#include "ParserDefinitionDecoder.hpp"
#define OUT_A_DEFINITION 309480394
#define IN_A_DEFINITION 309480392
using namespace std;
ParserDefinitionDecoder::ParserDefinitionDecoder(){
_state = OUT_A_DEFINITION;
}
int ParserDefinitionDecoder::definitions_number(){
return _definitions.size();
......@@ -9,7 +15,78 @@ int ParserDefinitionDecoder::definitions_number(){
void ParserDefinitionDecoder::store_definition(Line &line){
std::string first_token;
if (!line.item(1,first_token))
{
std::cout << "error : a definition line is empty" << endl;
return;
}
if (first_token == "EventDef"){
if (_state == IN_A_DEFINITION){
std::cout << "expected %EndDef" << endl;
return;
}
std::string definition_name;
if (!line.item(2,definition_name)){
std::cout << "a definition has no name" << endl;
return;
}
int definition_identity;
std::string definition_identity_string;
if (!line.item(3,definition_identity_string)){
std::cout<<"definition has no identifier"<<endl;
return;
}
if (sscanf(definition_identity_string.c_str(),"%d",&definition_identity)!=1){
std::cout<<"expected identifier for a definition"<<endl;
return;}
Definition current_definition = Definition(definition_name);
_definitions.insert(pair<int,Definition>(definition_identity, current_definition));
_current_definition = definition_identity;
if (line.length()>4){
std::cout<<"warning extra token in %EvenDef"<<endl;
}
_state = IN_A_DEFINITION;
return;
}
else if (first_token == "EndEventDef")
{
if (_state != IN_A_DEFINITION){
std::cout << "expected %EventDef" << endl;
return;
}
_state = OUT_A_DEFINITION;
if (line.length()>2){
std::cout<<"warning extra token in %EvenDef"<<endl;
}
}
else{
if (_state == OUT_A_DEFINITION){
std::cout << "expected %EventDef2" << endl;
return;
}
std::string field_value;
if (!line.item(2,field_value)){
std::cout << "A field type is missing." << endl;
return;
}
_definitions[_current_definition].store(first_token,field_value);
}
/*
//read the definition header
string &definition_name = line.item(2);
......@@ -48,7 +125,7 @@ void ParserDefinitionDecoder::store_definition(Line &line){
}
line.clear();
_definitions.insert(pair<int,Definition>(definition_identity, current_definition));
*/
}
Definition& ParserDefinitionDecoder::get_definition(int i){
......
......@@ -23,8 +23,11 @@ class ParserDefinitionDecoder{
private:
/*! \brief Hash table to retrive easily event in Parser Event. */
std::map<int,Definition> _definitions;
int _state;
int _current_definition;
public:
public:
ParserDefinitionDecoder();
int definitions_number();
void store_definition(Line &);
Definition& get_definition(int i);
......
#include "ParserEventDecoder.hpp"
ParserEventDecoder::ParserEventDecoder(std::map<int,Definition>* table){
_definitions_ptr = table;
ParserEventDecoder::ParserEventDecoder(){
}
......
......@@ -28,7 +28,7 @@ private:
public:
ParserEventDecoder(std::map<int,Definition>*);
ParserEventDecoder();
void sort_definition(Definition& d,Line&);
......
......@@ -7,6 +7,8 @@ void ParserPaje::parse(string filename, Trace &trace){
//ParserEventDecoder* parser_event_decoder = new ParserEventDecoder(&parser_definition_decoder);
Line line(filename);
int countline = 0;
while(!line.eof()){
// store the first line of the file
......
......@@ -9,14 +9,16 @@ using namespace std;
int main(int argc, char **argv){
ParserDefinitionDecoder *parserdefinition = new ParserDefinitionDecoder();
ParserEventDecoder *parserevent = new ParserEventDecoder(parserdefinition->HashTableofDefinitions());
ParserEventDecoder *parserevent = new ParserEventDecoder();
Line line("trace_to_parse.trace");
int linescount = 0;
int linecount = 0;
std::string pourcent = "%";
while(!line.eof()){
while(!line.eof()){
line.newline();
if(line.starts_with(pourcent)){
......@@ -25,16 +27,21 @@ int main(int argc, char **argv){
else
{
int number;
if (sscanf(line.item(0).c_str(),"%d",&number)!=1)
std::string token;
if (!line.item(0,token))
std::cout<<"line is empty"<<endl;
if (sscanf(token.c_str(),"%d",&number)!=1)
std::cout<<"NAN"<<endl;
else
parserevent->sort_definition(parserdefinition->get_definition(number),line);
//parserevent->sort_definition(parserdefinition->get_definition(number),line);
linecount++;
}
}
//parserdefinition->print_definitions();
parserdefinition->print_definitions();
std::cout << "lu :" << linecount;
delete parserdefinition;
delete parserevent;
......
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