Verified Commit 5a261c19 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Dynare++: modernize Bison and Flex stuff

parent 9ab832de
......@@ -65,6 +65,14 @@ AC_PROG_MKDIR_P
AX_CXX11_THREAD
AM_PROG_LEX
AC_CHECK_PROG([YACC], [bison], [bison])
if test -z "$YACC"; then
unset YACC # AM_MISSING_PROG needs an unset variable: an empty variable won't do
AM_MISSING_PROG([YACC], [bison])
fi
# Check for libmatio, needed by Dynare++
AX_MATIO
AM_CONDITIONAL([HAVE_MATIO], [test "$has_matio" = yes])
......
......@@ -36,7 +36,7 @@ BUILT_SOURCES = $(GENERATED_FILES)
EXTRA_DIST = assign.yy csv.yy formula.yy matrix.yy namelist.yy assign.ll csv.ll formula.ll matrix.ll namelist.ll
%_tab.cc %_tab.hh: %.yy
$(YACC) -d -o$*_tab.cc $<
$(YACC) -W -o$*_tab.cc $<
%_ll.cc: %.ll
$(LEX) -i -o$@ $<
......@@ -3,8 +3,6 @@
#include "location.hh"
#include "assign_tab.hh"
extern YYLTYPE asgn_lloc;
#define YY_USER_ACTION SET_LLOC(asgn_);
%}
......@@ -44,12 +42,14 @@
%%
int asgn_wrap()
int
asgn_wrap()
{
return 1;
return 1;
}
void asgn__destroy_buffer(void* p)
void
asgn__destroy_buffer(void* p)
{
asgn__delete_buffer((YY_BUFFER_STATE)p);
asgn__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
}
// -*- C++ -*-
%{
/* Copyright © 2006-2011, Ondra Kamenik */
%code requires
{
#include "location.hh"
#include "atom_assignings.hh"
#include "assign_tab.hh"
#include <stdio.h>
#define ASGN_LTYPE ogp::location_type
}
void asgn_error(const char*);
int asgn_lex(void);
extern int asgn_lineno;
extern ogp::AtomAssignings* aparser;
%code
{
#include "atom_assignings.hh"
%}
void asgn_error(const char*);
int asgn_lex();
extern ogp::AtomAssignings* aparser;
}
%union {
int integer;
char *string;
char character;
%union
{
int integer;
char *string;
char character;
}
%token EQUAL_SIGN SEMICOLON CHARACTER BLANK
%token <string> NAME;
%name-prefix="asgn_"
%define api.prefix {asgn_}
%locations
%error-verbose
%defines
%define parse.error verbose
%%
root : assignments | ;
root : assignments | %empty;
assignments : assignments BLANK | assignments assignment | assignment | BLANK;
......@@ -47,7 +50,8 @@ space : space BLANK | BLANK;
%%
void asgn_error(const char* mes)
void
asgn_error(const char* mes)
{
aparser->error(mes);
aparser->error(mes);
}
......@@ -5,8 +5,6 @@
#include "location.hh"
#include "csv_tab.hh"
extern YYLTYPE csv_lloc;
#define YY_USER_ACTION SET_LLOC(csv_);
%}
......@@ -25,12 +23,14 @@
%%
int csv_wrap()
int
csv_wrap()
{
return 1;
return 1;
}
void csv__destroy_buffer(void* p)
void
csv__destroy_buffer(void* p)
{
csv__delete_buffer((YY_BUFFER_STATE)p);
csv__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
}
// -*- C++ -*-
%{
%code requires
{
#include "location.hh"
#define CSV_LTYPE ogp::location_type
}
%code
{
#include "csv_parser.hh"
#include "csv_tab.hh"
void csv_error(const char*);
int csv_lex(void);
extern int csv_lineno;
extern ogp::CSVParser* csv_parser;
extern YYLTYPE csv_lloc;
%}
%union {
char* string;
int integer;
void csv_error(const char*);
int csv_lex();
extern ogp::CSVParser* csv_parser;
}
%union
{
char* string;
int integer;
}
%token COMMA NEWLINE BOGUS
%token <string> ITEM
%name-prefix="csv_";
%define api.prefix {csv_};
%locations
%error-verbose
%defines
%define parse.error verbose
%%
......@@ -41,7 +46,8 @@ item : ITEM {csv_parser->item(@1.off, @1.ll);};
%%
void csv_error(const char* mes)
void
csv_error(const char* mes)
{
csv_parser->csv_error(mes);
csv_parser->csv_error(mes);
}
......@@ -3,8 +3,6 @@
#include "location.hh"
#include "formula_tab.hh"
extern YYLTYPE fmla_lloc;
#define YY_USER_ACTION SET_LLOC(fmla_);
%}
......@@ -62,12 +60,14 @@ diff {return YDIFF;}
%%
int fmla_wrap()
int
fmla_wrap()
{
return 1;
return 1;
}
void fmla__destroy_buffer(void* p)
void
fmla__destroy_buffer(void* p)
{
fmla__delete_buffer((YY_BUFFER_STATE)p);
fmla__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
}
// -*- C++ -*-
%{
/* Copyright © 2006-2011, Ondra Kamenik */
#include <cstdio>
%code requires
{
#include "location.hh"
#include "formula_parser.hh"
#include "formula_tab.hh"
void fmla_error(const char*);
int fmla_lex(void);
extern int fmla_lineno;
extern ogp::FormulaParser* fparser;
extern YYLTYPE fmla_lloc;
#define FMLA_LTYPE ogp::location_type
}
// static void print_token_value (FILE *, int, YYSTYPE);
// #define YYPRINT(file, type, value) print_token_value (file, type, value)
%code
{
#include "formula_parser.hh"
%}
void fmla_error(const char*);
int fmla_lex();
extern ogp::FormulaParser* fparser;
}
%union {
char* string;
double dvalue;
int integer;
%union
{
char* string;
double dvalue;
int integer;
}
%token EQUAL_SIGN
%left YPLUS YMINUS
%left YTIMES YDIVIDE
%left YUMINUS YUPLUS
%precedence YUMINUS YUPLUS
%right YPOWER
%token YEXP YLOG YSIN YCOS YTAN YSQRT YERF YERFC YDIFF
%token <string> DNUMBER NAME
%type <integer> expression
%name-prefix="fmla_"
%define api.prefix {fmla_}
%locations
%error-verbose
%defines
%define parse.error verbose
%%
root : equation_list
......@@ -76,15 +75,8 @@
%%
void fmla_error(const char* s)
{
fparser->error(s);
}
/*
static void print_token_value(FILE* file, int type, YYSTYPE value)
void
fmla_error(const char* s)
{
if (type == NAME)
fprintf(file, "%s", value.string);
fparser->error(s);
}
*/
......@@ -20,24 +20,22 @@
namespace ogp
{
struct location_type
{
int off{0}; // offset of the token
int ll{0}; // length ot the token
location_type()
= default;
location_type() = default;
};
};
#define YYLTYPE ogp::location_type
// set current off to the first off and add all lengths
#define YYLLOC_DEFAULT(Current, Rhs, N) \
{(Current).off = (Rhs)[1].off; \
(Current).ll = 0; \
for (int i = 1; i <= N; i++) (Current).ll += (Rhs)[i].ll; }
{ \
(Current).off = (Rhs)[1].off; \
(Current).ll = 0; \
for (int i = 1; i <= N; i++) \
(Current).ll += (Rhs)[i].ll; \
}
#define SET_LLOC(prefix) (prefix ## lloc.off += prefix ## lloc.ll, prefix ## lloc.ll = prefix ## leng)
......
......@@ -5,8 +5,7 @@
#include "location.hh"
#include "matrix_tab.hh"
extern YYLTYPE matrix_lloc;
extern void matrix_error(const char*);
extern void matrix_error(const char*);
#define YY_USER_ACTION SET_LLOC(matrix_);
%}
......@@ -51,12 +50,14 @@
%%
int matrix_wrap()
int
matrix_wrap()
{
return 1;
return 1;
}
void matrix__destroy_buffer(void* p)
void
matrix__destroy_buffer(void* p)
{
matrix__delete_buffer((YY_BUFFER_STATE)p);
matrix__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
}
// -*- C++ -*-
// Copyright © 2006-2011, Ondra Kamenik
%{
%code requires
{
#include "location.hh"
#include "matrix_parser.hh"
#include "matrix_tab.hh"
void matrix_error(const char*);
int matrix_lex(void);
extern int matrix_lineno;
extern ogp::MatrixParser* mparser;
extern YYLTYPE matrix_lloc;
#define MATRIX_LTYPE ogp::location_type
}
// static void print_token_value (FILE *, int, YYSTYPE);
//#define YYPRINT(file, type, value) print_token_value (file, type, value)
%code
{
#include "matrix_parser.hh"
%}
void matrix_error(const char*);
int matrix_lex();
extern ogp::MatrixParser* mparser;
}
%union {
double val;
int integer;
%union
{
double val;
int integer;
}
%token NEW_ROW
%token <val> DNUMBER
%name-prefix="matrix_";
%define api.prefix {matrix_};
%locations
%error-verbose
%defines
%define parse.error verbose
%%
......@@ -61,9 +62,10 @@ one_row : NEW_ROW {mparser->start_row();} lod;
%%
void matrix_error(const char* s)
void
matrix_error(const char* s)
{
mparser->error(s);
mparser->error(s);
}
......@@ -3,8 +3,6 @@
#include "location.hh"
#include "namelist_tab.hh"
extern YYLTYPE namelist_lloc;
#define YY_USER_ACTION SET_LLOC(namelist_);
%}
......@@ -42,12 +40,14 @@
%%
int namelist_wrap()
int
namelist_wrap()
{
return 1;
return 1;
}
void namelist__destroy_buffer(void* p)
void
namelist__destroy_buffer(void* p)
{
namelist__delete_buffer((YY_BUFFER_STATE)p);
namelist__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
}
// -*- C++ -*-
// Copyright © 2007-2011, Ondra Kamenik
%{
%code requires
{
#include "location.hh"
#include "namelist.hh"
#include "namelist_tab.hh"
#define NAMELIST_LTYPE ogp::location_type
}
void namelist_error(const char*);
int namelist_lex(void);
extern ogp::NameListParser* name_list_parser;
%code
{
#include "namelist.hh"
%}
void namelist_error(const char*);
int namelist_lex();
extern ogp::NameListParser* name_list_parser;
}
%union {
int integer;
char *string;
char character;
%union
{
int integer;
char *string;
char character;
}
%token COMMA CHARACTER
%token <string> NAME;
%name-prefix="namelist_"
%define api.prefix {namelist_}
%locations
%error-verbose
%defines
%define parse.error verbose
%%
......@@ -35,7 +41,8 @@ namelist : namelist NAME {name_list_parser->add_name($2);}
%%
void namelist_error(const char* mes)
void
namelist_error(const char* mes)
{
name_list_parser->namelist_error(mes);
name_list_parser->namelist_error(mes);
}
......@@ -30,7 +30,7 @@ BUILT_SOURCES = $(GENERATED_FILES)
EXTRA_DIST = dynglob.ll dynglob.yy
dynglob_tab.cc dynglob_tab.hh: dynglob.yy
$(YACC) -d -odynglob_tab.cc dynglob.yy
$(YACC) -W -odynglob_tab.cc dynglob.yy
dynglob_ll.cc: dynglob.ll
$(LEX) -i -odynglob_ll.cc dynglob.ll
......@@ -3,8 +3,6 @@
#include "parser/cc/location.hh"
#include "dynglob_tab.hh"
extern YYLTYPE dynglob_lloc;
#define YY_USER_ACTION SET_LLOC(dynglob_);
%}
......@@ -58,12 +56,14 @@ planner_discount {return PLANNERDISCOUNT;}
%%
int dynglob_wrap()
int
dynglob_wrap()
{
return 1;
return 1;
}
void dynglob__destroy_buffer(void* p)
void
dynglob__destroy_buffer(void* p)
{
dynglob__delete_buffer((YY_BUFFER_STATE)p);
dynglob__delete_buffer(reinterpret_cast<YY_BUFFER_STATE>(p));
}
// -*- C++ -*-
%{
// Copyright © 2006-2011, Ondra Kamenik
%code requires
{
#include "parser/cc/location.hh"
#include "dynare_model.hh"
#include "dynglob_tab.hh"
#include <stdio.h>
void dynglob_error(const char*);
int dynglob_lex(void);
extern int dynglob_lineno;
extern ogdyn::DynareParser* dynare_parser;
int symblist_flag;
#define DYNGLOB_LTYPE ogp::location_type
}
// static void print_token_value1 (FILE *, int, YYSTYPE);
//#define YYPRINT(file, type, value) print_token_value1 (file, type, value)
%code
{
#include "dynare_model.hh"
%}
void dynglob_error(const char*);
int dynglob_lex();
extern ogdyn::DynareParser* dynare_parser;
int symblist_flag;
}
%union {
int integer;
char *string;
char character;
%union
{
int integer;
char *string;
char character;
}
%token END INITVAL MODEL PARAMETERS VAR VAREXO SEMICOLON COMMA EQUAL_SIGN CHARACTER
%token VCOV LEFT_BRACKET RIGHT_BRACKET ORDER PLANNEROBJECTIVE PLANNERDISCOUNT
%token <string> NAME;
%name-prefix="dynglob_"
%define api.prefix {dynglob_}
%locations
%error-verbose
%defines
%define parse.error verbose
%%
......@@ -108,17 +108,8 @@ planner_discount : PLANNERDISCOUNT NAME SEMICOLON {
%%
void dynglob_error(const char* mes)
{
dynare_parser->error(mes);
}
/*
static void print_token_value1(FILE* file, int type, YYSTYPE value)
void