2014-02-06 18:52:13 +00:00
|
|
|
/*
|
|
|
|
* IoAsciiParser.ypp, part of LatAnalyze 3
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 - 2014 Antonin Portelli
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-05-21 18:02:42 +01:00
|
|
|
%{
|
|
|
|
#include <iostream>
|
2014-02-13 19:23:39 +00:00
|
|
|
#include <memory>
|
2013-05-21 18:02:42 +01:00
|
|
|
#include <sstream>
|
2014-02-13 19:23:39 +00:00
|
|
|
#include <utility>
|
2013-05-21 18:02:42 +01:00
|
|
|
#include <cstring>
|
|
|
|
#include <latan/Global.hpp>
|
|
|
|
#include <latan/IO.hpp>
|
2014-02-10 16:01:39 +00:00
|
|
|
#include <latan/Mat.hpp>
|
|
|
|
#include <latan/RandGen.hpp>
|
2013-05-21 18:02:42 +01:00
|
|
|
#include <latan/Sample.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Latan;
|
2014-02-13 19:23:39 +00:00
|
|
|
|
2014-02-17 18:46:55 +00:00
|
|
|
#define TEST_FIRST(name) \
|
|
|
|
if (state->isFirst)\
|
|
|
|
{\
|
|
|
|
state->first = (name);\
|
|
|
|
state->isFirst = false;\
|
|
|
|
}
|
2013-05-21 18:02:42 +01:00
|
|
|
%}
|
|
|
|
|
|
|
|
%pure-parser
|
2014-01-22 15:57:47 +00:00
|
|
|
%name-prefix="_ioAscii_"
|
2013-05-21 18:02:42 +01:00
|
|
|
%locations
|
|
|
|
%defines
|
|
|
|
%error-verbose
|
2014-02-06 18:08:46 +00:00
|
|
|
%parse-param { Latan::AsciiFile::AsciiParserState* state }
|
2013-05-21 18:02:42 +01:00
|
|
|
%initial-action {yylloc.last_column = 0;}
|
|
|
|
%lex-param { void* scanner }
|
|
|
|
|
|
|
|
%union
|
|
|
|
{
|
2014-02-13 19:23:39 +00:00
|
|
|
int val_int;
|
|
|
|
double val_double;
|
|
|
|
char val_char;
|
|
|
|
char val_str[256];
|
2013-05-21 18:02:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
%token <val_char> ERR
|
|
|
|
%token <val_double> FLOAT
|
|
|
|
%token <val_int> INT
|
|
|
|
%token <val_str> ID
|
2014-02-17 18:46:55 +00:00
|
|
|
%token OPEN CLOSE MAT SAMPLE RG_STATE
|
2014-02-13 19:23:39 +00:00
|
|
|
|
2014-02-17 18:46:55 +00:00
|
|
|
%type <val_str> mat sample rg_state
|
2013-05-21 18:02:42 +01:00
|
|
|
|
|
|
|
%{
|
2014-01-22 15:57:47 +00:00
|
|
|
int _ioAscii_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
|
2013-05-21 18:02:42 +01:00
|
|
|
|
2014-02-06 18:08:46 +00:00
|
|
|
void _ioAscii_error(YYLTYPE* locp, AsciiFile::AsciiParserState* state,
|
|
|
|
const char* err)
|
2013-05-21 18:02:42 +01:00
|
|
|
{
|
|
|
|
stringstream buf;
|
|
|
|
|
2014-01-22 15:57:47 +00:00
|
|
|
buf << *state->streamName << ":" << locp->first_line << ":"\
|
2013-05-21 18:02:42 +01:00
|
|
|
<< locp->first_column << ": " << err;
|
2014-01-22 15:57:47 +00:00
|
|
|
LATAN_ERROR(Parsing, buf.str());
|
2013-05-21 18:02:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define scanner state->scanner
|
|
|
|
%}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
datas:
|
|
|
|
/* empty string */
|
2014-02-10 16:01:39 +00:00
|
|
|
| datas data
|
2013-05-21 18:02:42 +01:00
|
|
|
;
|
|
|
|
|
2014-02-10 16:01:39 +00:00
|
|
|
data:
|
|
|
|
mat
|
2014-02-18 18:10:09 +00:00
|
|
|
{
|
|
|
|
TEST_FIRST($1);
|
|
|
|
(*state->data)[$1].reset(new DMat(state->dMatQueue.front()));
|
|
|
|
state->dMatQueue.pop();
|
|
|
|
}
|
2014-02-17 18:46:55 +00:00
|
|
|
| sample
|
2014-02-18 18:10:09 +00:00
|
|
|
{
|
|
|
|
TEST_FIRST($1);
|
|
|
|
(*state->data)[$1].reset(new DMatSample(state->dMatSampleBuf));
|
|
|
|
}
|
2014-02-10 16:01:39 +00:00
|
|
|
| rg_state
|
2014-02-18 18:10:09 +00:00
|
|
|
{
|
|
|
|
TEST_FIRST($1);
|
|
|
|
(*state->data)[$1].reset(new RandGen::State(state->stateBuf));
|
|
|
|
}
|
2014-02-10 16:01:39 +00:00
|
|
|
;
|
|
|
|
|
2013-05-21 18:02:42 +01:00
|
|
|
mat:
|
|
|
|
OPEN MAT ID INT floats CLOSE MAT
|
|
|
|
{
|
2014-02-17 18:46:55 +00:00
|
|
|
const unsigned int nRow = state->doubleQueue.size()/$INT, nCol = $INT;
|
|
|
|
int i, j, r = 0;
|
|
|
|
|
|
|
|
if (state->doubleQueue.size() != nRow*nCol)
|
|
|
|
{
|
|
|
|
LATAN_ERROR(Size, "matrix '" + *state->streamName + ":" + $ID +
|
|
|
|
"' has a wrong size");
|
|
|
|
}
|
2013-05-21 18:02:42 +01:00
|
|
|
|
2014-02-17 18:46:55 +00:00
|
|
|
state->dMatQueue.push(DMat(nRow, nCol));
|
|
|
|
while (!state->doubleQueue.empty())
|
2013-05-21 18:02:42 +01:00
|
|
|
{
|
2014-01-22 15:57:47 +00:00
|
|
|
j = r % nCol;
|
|
|
|
i = (r - j)/nCol;
|
2014-02-17 18:46:55 +00:00
|
|
|
state->dMatQueue.back()(i, j) = state->doubleQueue.front();
|
|
|
|
state->doubleQueue.pop();
|
|
|
|
r++;
|
2013-05-21 18:02:42 +01:00
|
|
|
}
|
2014-02-17 18:46:55 +00:00
|
|
|
strcpy($$, $ID);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
sample:
|
|
|
|
OPEN SAMPLE ID INT mats CLOSE SAMPLE
|
|
|
|
{
|
|
|
|
const unsigned int nSample = $INT + 1;
|
|
|
|
|
|
|
|
if (state->dMatQueue.size() != nSample)
|
2014-02-10 16:01:39 +00:00
|
|
|
{
|
2014-02-17 18:46:55 +00:00
|
|
|
LATAN_ERROR(Size, "sample '" + *state->streamName + ":" + $ID +
|
2014-02-10 16:01:39 +00:00
|
|
|
"' has a wrong size");
|
|
|
|
}
|
2014-02-17 18:46:55 +00:00
|
|
|
state->dMatSampleBuf.resize(nSample);
|
|
|
|
state->dMatSampleBuf[central] = state->dMatQueue.front();
|
|
|
|
state->dMatQueue.pop();
|
|
|
|
for (int i = 0; i < $INT; ++i)
|
|
|
|
{
|
|
|
|
state->dMatSampleBuf[i] = state->dMatQueue.front();
|
|
|
|
state->dMatQueue.pop();
|
|
|
|
}
|
2014-02-13 19:23:39 +00:00
|
|
|
strcpy($$, $ID);
|
2014-02-10 16:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rg_state:
|
|
|
|
OPEN RG_STATE ID ints CLOSE RG_STATE
|
|
|
|
{
|
2014-02-17 18:46:55 +00:00
|
|
|
if (state->intQueue.size() != RLXG_STATE_SIZE)
|
2014-02-10 16:01:39 +00:00
|
|
|
{
|
2014-02-17 18:46:55 +00:00
|
|
|
LATAN_ERROR(Size, "random generator state '" + *state->streamName
|
|
|
|
+ ":" + $ID + "' has a wrong size");
|
2014-02-10 16:01:39 +00:00
|
|
|
}
|
2014-02-17 18:46:55 +00:00
|
|
|
for (unsigned int i = 0; i < RLXG_STATE_SIZE; ++i)
|
2014-02-10 16:01:39 +00:00
|
|
|
{
|
2014-02-17 18:46:55 +00:00
|
|
|
state->stateBuf[i] = state->intQueue.front();
|
|
|
|
state->intQueue.pop();
|
2014-02-10 16:01:39 +00:00
|
|
|
}
|
2014-02-13 19:23:39 +00:00
|
|
|
strcpy($$, $ID);
|
2013-05-21 18:02:42 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-17 18:46:55 +00:00
|
|
|
mats:
|
|
|
|
mats mat
|
|
|
|
| mat
|
|
|
|
;
|
|
|
|
|
2013-05-21 18:02:42 +01:00
|
|
|
floats:
|
2014-02-17 18:46:55 +00:00
|
|
|
floats FLOAT {state->doubleQueue.push($FLOAT);}
|
|
|
|
| floats INT {state->doubleQueue.push(static_cast<double>($INT));}
|
|
|
|
| FLOAT {state->doubleQueue.push($FLOAT);}
|
|
|
|
| INT {state->doubleQueue.push(static_cast<double>($INT));}
|
2013-05-21 18:02:42 +01:00
|
|
|
;
|
2014-02-10 16:01:39 +00:00
|
|
|
|
|
|
|
ints:
|
2014-02-17 18:46:55 +00:00
|
|
|
ints INT {state->intQueue.push($INT);}
|
|
|
|
| INT {state->intQueue.push($INT);}
|
2014-02-10 16:01:39 +00:00
|
|
|
;
|