2011-04-18 20:29:07 +02:00
|
|
|
|
|
|
|
|
%{
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2011 Cary R. (cygcary@yahoo.com)
|
|
|
|
|
*
|
|
|
|
|
* This program 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 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-05-02 18:17:34 +02:00
|
|
|
#include <assert.h>
|
2011-04-18 20:29:07 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "table_mod.h"
|
2011-05-02 18:17:34 +02:00
|
|
|
#include "ivl_alloc.h"
|
2011-04-18 20:29:07 +02:00
|
|
|
|
|
|
|
|
static unsigned minimum_columns;
|
2011-05-02 18:17:34 +02:00
|
|
|
static unsigned indep_columns;
|
|
|
|
|
static unsigned dep_column;
|
|
|
|
|
static unsigned number_of_columns = 0;
|
2011-04-18 20:29:07 +02:00
|
|
|
static unsigned cur_columns;
|
2011-05-02 18:17:34 +02:00
|
|
|
static double *values;
|
2011-04-18 20:29:07 +02:00
|
|
|
static const char *in_file_name;
|
|
|
|
|
|
|
|
|
|
extern int tblmodlex(void);
|
|
|
|
|
static void yyerror(const char *fmt, ...);
|
|
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%locations
|
|
|
|
|
|
|
|
|
|
%union {
|
|
|
|
|
double real;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
%token EOL
|
|
|
|
|
%token <real> REAL
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
table : point
|
|
|
|
|
| table point
|
|
|
|
|
|
|
|
|
|
point : columns EOL
|
|
|
|
|
{
|
2011-05-02 18:17:34 +02:00
|
|
|
unsigned idx;
|
|
|
|
|
fprintf(stderr, "%#g", values[0]);
|
|
|
|
|
for (idx = 1; idx < indep_columns; idx += 1) {
|
|
|
|
|
fprintf(stderr, ", %#g", values[idx]);
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, " => %#g\n", values[indep_columns]);
|
2011-04-18 20:29:07 +02:00
|
|
|
if (number_of_columns) {
|
2011-05-02 18:17:34 +02:00
|
|
|
if (cur_columns < minimum_columns) {
|
|
|
|
|
yyerror("Found %u columns, need at least %u.",
|
|
|
|
|
cur_columns, minimum_columns);
|
|
|
|
|
} else if (cur_columns != number_of_columns) {
|
2011-04-18 20:29:07 +02:00
|
|
|
yyerror("Found %u columns, expected %u.",
|
|
|
|
|
cur_columns, number_of_columns);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (cur_columns < minimum_columns) {
|
|
|
|
|
yyerror("Found %u columns, need at least %u.",
|
|
|
|
|
cur_columns, minimum_columns);
|
2011-05-02 18:17:34 +02:00
|
|
|
} else number_of_columns = cur_columns;
|
2011-04-18 20:29:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
columns : REAL
|
|
|
|
|
{
|
2011-05-02 18:17:34 +02:00
|
|
|
values[0] = $1;
|
|
|
|
|
cur_columns = 1;
|
2011-04-18 20:29:07 +02:00
|
|
|
}
|
|
|
|
|
| columns REAL
|
|
|
|
|
{
|
2011-05-02 18:17:34 +02:00
|
|
|
if (cur_columns < indep_columns) values[cur_columns] = $2;
|
|
|
|
|
else if (cur_columns == dep_column) values[indep_columns] = $2;
|
|
|
|
|
cur_columns += 1;
|
2011-04-18 20:29:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
int parse_table_model(FILE *fp, const char *file_name, vpiHandle callh,
|
2011-05-02 18:17:34 +02:00
|
|
|
unsigned indep_cols, unsigned dep_col)
|
2011-04-18 20:29:07 +02:00
|
|
|
{
|
2011-05-02 18:17:34 +02:00
|
|
|
assert(indep_cols > 1);
|
|
|
|
|
assert(dep_col > 0);
|
|
|
|
|
indep_columns = indep_cols;
|
|
|
|
|
minimum_columns = indep_cols + dep_col;
|
|
|
|
|
dep_column = minimum_columns - 1;
|
|
|
|
|
values = malloc(sizeof(double)*(indep_cols+1));
|
|
|
|
|
assert(values);
|
2011-04-18 20:29:07 +02:00
|
|
|
in_file_name = file_name;
|
|
|
|
|
init_tblmod_lexor(fp);
|
|
|
|
|
yyparse();
|
|
|
|
|
destroy_tblmod_lexor();
|
2011-05-02 18:17:34 +02:00
|
|
|
free(values);
|
2011-04-18 20:29:07 +02:00
|
|
|
// HERE: Need to handle errors.
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void yyerror(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
fprintf(stderr, "%s:%u: TABLE ERROR: ", in_file_name, yylloc.first_line);
|
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
|
|
}
|