Commit 2bd9acba authored by Francis Dupont's avatar Francis Dupont
Browse files

[master] Merged trac5060 (specialize eval flex/bison)

parents 926479dd 7089c825
......@@ -94,7 +94,7 @@ location.hh position.hh stack.hh parser.cc parser.h: parser.yy
$(YACC) --defines=parser.h -o parser.cc parser.yy
lexer.cc: lexer.ll
$(LEX) -o lexer.cc lexer.ll
$(LEX) --prefix eval -o lexer.cc lexer.ll
else
......
......@@ -13,7 +13,8 @@
#include <exceptions/exceptions.h>
// Tell Flex the lexer's prototype ...
#define YY_DECL isc::eval::EvalParser::symbol_type yylex (EvalContext& driver)
#define YY_DECL \
isc::eval::EvalParser::symbol_type evallex (EvalContext& driver)
// ... and declare it for the parser's sake.
YY_DECL;
......
This diff is collapsed.
......@@ -43,7 +43,7 @@ static isc::eval::location loc;
%option batch
/* Enables debug mode. To see the debug messages, one needs to also set
yy_flex_debug to 1, then the debug messages will be printed on stderr. */
eval_flex_debug to 1, then the debug messages will be printed on stderr. */
%option debug
/* I have no idea what this option does, except it was specified in the bison
......@@ -69,13 +69,13 @@ addr6 [0-9a-fA-F]*\:[0-9a-fA-F]*\:[0-9a-fA-F:.]*
// This code run each time a pattern is matched. It updates the location
// by moving it ahead by yyleng bytes. yyleng specifies the length of the
// currently matched token.
#define YY_USER_ACTION loc.columns(yyleng);
#define YY_USER_ACTION loc.columns(evalleng);
%}
%%
%{
// Code run each time yylex is called.
// Code run each time evallex is called.
loc.step();
%}
......@@ -85,7 +85,7 @@ addr6 [0-9a-fA-F]*\:[0-9a-fA-F]*\:[0-9a-fA-F:.]*
}
[\n]+ {
// Newline found. Let's update the location and continue.
loc.lines(yyleng);
loc.lines(evalleng);
loc.step();
}
......@@ -93,7 +93,7 @@ addr6 [0-9a-fA-F]*\:[0-9a-fA-F]*\:[0-9a-fA-F:.]*
// A string has been matched. It contains the actual string and single quotes.
// We need to get those quotes out of the way and just use its content, e.g.
// for 'foo' we should get foo
std::string tmp(yytext+1);
std::string tmp(evaltext+1);
tmp.resize(tmp.size() - 1);
return isc::eval::EvalParser::make_STRING(tmp, loc);
......@@ -102,12 +102,12 @@ addr6 [0-9a-fA-F]*\:[0-9a-fA-F]*\:[0-9a-fA-F:.]*
0[xX]{hex} {
// A hex string has been matched. It contains the '0x' or '0X' header
// followed by at least one hexadecimal digit.
return isc::eval::EvalParser::make_HEXSTRING(yytext, loc);
return isc::eval::EvalParser::make_HEXSTRING(evaltext, loc);
}
{int} {
// An integer was found.
std::string tmp(yytext);
std::string tmp(evaltext);
try {
// In substring we want to use negative values (e.g. -1).
......@@ -127,12 +127,12 @@ addr6 [0-9a-fA-F]*\:[0-9a-fA-F]*\:[0-9a-fA-F:.]*
// This string specifies option name starting with a letter
// and further containing letters, digits, hyphens and
// underscores and finishing by letters or digits.
return isc::eval::EvalParser::make_OPTION_NAME(yytext, loc);
return isc::eval::EvalParser::make_OPTION_NAME(evaltext, loc);
}
{addr4}|{addr6} {
// IPv4 or IPv6 address
std::string tmp(yytext);
std::string tmp(evaltext);
// Some incorrect addresses can match so we have to check.
try {
......@@ -141,7 +141,7 @@ addr6 [0-9a-fA-F]*\:[0-9a-fA-F]*\:[0-9a-fA-F:.]*
driver.error(loc, "Failed to convert " + tmp + " to an IP address.");
}
return isc::eval::EvalParser::make_IP_ADDRESS(yytext, loc);
return isc::eval::EvalParser::make_IP_ADDRESS(evaltext, loc);
}
"==" return isc::eval::EvalParser::make_EQUAL(loc);
......@@ -186,7 +186,7 @@ addr6 [0-9a-fA-F]*\:[0-9a-fA-F]*\:[0-9a-fA-F:.]*
"]" return isc::eval::EvalParser::make_RBRACKET(loc);
"," return isc::eval::EvalParser::make_COMA(loc);
"*" return isc::eval::EvalParser::make_ANY(loc);
. driver.error (loc, "Invalid character: " + std::string(yytext));
. driver.error (loc, "Invalid character: " + std::string(evaltext));
<<EOF>> return isc::eval::EvalParser::make_END(loc);
%%
......@@ -196,9 +196,9 @@ void
EvalContext::scanStringBegin()
{
loc.initialize(&file_);
yy_flex_debug = trace_scanning_;
eval_flex_debug = trace_scanning_;
YY_BUFFER_STATE buffer;
buffer = yy_scan_bytes(string_.c_str(), string_.size());
buffer = eval_scan_bytes(string_.c_str(), string_.size());
if (!buffer) {
fatal("cannot scan string");
// fatal() throws an exception so this can't be reached
......@@ -208,7 +208,7 @@ EvalContext::scanStringBegin()
void
EvalContext::scanStringEnd()
{
yy_delete_buffer(YY_CURRENT_BUFFER);
eval_delete_buffer(YY_CURRENT_BUFFER);
}
namespace {
......
// Generated 201609071312
// Generated 201611011345
// A Bison parser, made by GNU Bison 3.0.4.
// Locations for Bison parsers in C++
......@@ -36,12 +36,12 @@
** Define the isc::eval::location class.
*/
#ifndef YY_YY_LOCATION_HH_INCLUDED
# define YY_YY_LOCATION_HH_INCLUDED
#ifndef YY_EVAL_LOCATION_HH_INCLUDED
# define YY_EVAL_LOCATION_HH_INCLUDED
# include "position.hh"
#line 13 "parser.yy" // location.cc:296
#line 14 "parser.yy" // location.cc:296
namespace isc { namespace eval {
#line 46 "location.hh" // location.cc:296
/// Abstract a location.
......@@ -187,7 +187,7 @@ namespace isc { namespace eval {
return ostr;
}
#line 13 "parser.yy" // location.cc:296
#line 14 "parser.yy" // location.cc:296
} } // isc::eval
#line 192 "location.hh" // location.cc:296
#endif // !YY_YY_LOCATION_HH_INCLUDED
#endif // !YY_EVAL_LOCATION_HH_INCLUDED
This diff is collapsed.
......@@ -37,10 +37,10 @@
// C++ LALR(1) parser skeleton written by Akim Demaille.
#ifndef YY_YY_PARSER_H_INCLUDED
# define YY_YY_PARSER_H_INCLUDED
#ifndef YY_EVAL_PARSER_H_INCLUDED
# define YY_EVAL_PARSER_H_INCLUDED
// // "%code requires" blocks.
#line 16 "parser.yy" // lalr1.cc:377
#line 17 "parser.yy" // lalr1.cc:377
#include <string>
#include <eval/token.h>
......@@ -122,13 +122,21 @@ using namespace isc::eval;
#endif
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#line 13 "parser.yy" // lalr1.cc:377
#ifndef EVALDEBUG
# if defined YYDEBUG
#if YYDEBUG
# define EVALDEBUG 1
# else
# define EVALDEBUG 0
# endif
# else /* ! defined YYDEBUG */
# define EVALDEBUG 1
# endif /* ! defined YYDEBUG */
#endif /* ! defined EVALDEBUG */
#line 14 "parser.yy" // lalr1.cc:377
namespace isc { namespace eval {
#line 132 "parser.h" // lalr1.cc:377
#line 140 "parser.h" // lalr1.cc:377
......@@ -291,7 +299,7 @@ namespace isc { namespace eval {
class EvalParser
{
public:
#ifndef YYSTYPE
#ifndef EVALSTYPE
/// An auxiliary type to compute the largest semantic type.
union union_type
{
......@@ -331,7 +339,7 @@ namespace isc { namespace eval {
/// Symbol semantic values.
typedef variant<sizeof(union_type)> semantic_type;
#else
typedef YYSTYPE semantic_type;
typedef EVALSTYPE semantic_type;
#endif
/// Symbol locations.
typedef location location_type;
......@@ -719,7 +727,7 @@ namespace isc { namespace eval {
/// \returns 0 iff parsing succeeded.
virtual int parse ();
#if YYDEBUG
#if EVALDEBUG
/// The current debugging stream.
std::ostream& debug_stream () const YY_ATTRIBUTE_PURE;
/// Set the current debugging stream.
......@@ -814,7 +822,7 @@ namespace isc { namespace eval {
/// For a symbol, its name in clear.
static const char* const yytname_[];
#if YYDEBUG
#if EVALDEBUG
// YYRLINE[YYN] -- Source line where rule number YYN was defined.
static const unsigned short int yyrline_[];
/// Report on the debug stream that the rule \a r is going to be reduced.
......@@ -1663,11 +1671,11 @@ namespace isc { namespace eval {
}
#line 13 "parser.yy" // lalr1.cc:377
#line 14 "parser.yy" // lalr1.cc:377
} } // isc::eval
#line 1669 "parser.h" // lalr1.cc:377
#line 1677 "parser.h" // lalr1.cc:377
#endif // !YY_YY_PARSER_H_INCLUDED
#endif // !YY_EVAL_PARSER_H_INCLUDED
......@@ -8,6 +8,7 @@
%require "3.0.0"
%defines
%define parser_class_name {EvalParser}
%define api.prefix {eval}
%define api.token.constructor
%define api.value.type variant
%define api.namespace {isc::eval}
......
// Generated 201609071312
// Generated 201611011345
// A Bison parser, made by GNU Bison 3.0.4.
// Positions for Bison parsers in C++
......@@ -36,8 +36,8 @@
** Define the isc::eval::position class.
*/
#ifndef YY_YY_POSITION_HH_INCLUDED
# define YY_YY_POSITION_HH_INCLUDED
#ifndef YY_EVAL_POSITION_HH_INCLUDED
# define YY_EVAL_POSITION_HH_INCLUDED
# include <algorithm> // std::max
# include <iostream>
......@@ -51,7 +51,7 @@
# endif
# endif
#line 13 "parser.yy" // location.cc:296
#line 14 "parser.yy" // location.cc:296
namespace isc { namespace eval {
#line 56 "position.hh" // location.cc:296
/// Abstract a position.
......@@ -175,7 +175,7 @@ namespace isc { namespace eval {
return ostr << pos.line << '.' << pos.column;
}
#line 13 "parser.yy" // location.cc:296
#line 14 "parser.yy" // location.cc:296
} } // isc::eval
#line 180 "position.hh" // location.cc:296
#endif // !YY_YY_POSITION_HH_INCLUDED
#endif // !YY_EVAL_POSITION_HH_INCLUDED
// Generated 201609071312
// Generated 201611011345
// A Bison parser, made by GNU Bison 3.0.4.
// Stack handling for Bison parsers in C++
......@@ -36,12 +36,12 @@
** Define the isc::eval::stack class.
*/
#ifndef YY_YY_STACK_HH_INCLUDED
# define YY_YY_STACK_HH_INCLUDED
#ifndef YY_EVAL_STACK_HH_INCLUDED
# define YY_EVAL_STACK_HH_INCLUDED
# include <vector>
#line 13 "parser.yy" // stack.hh:132
#line 14 "parser.yy" // stack.hh:132
namespace isc { namespace eval {
#line 46 "stack.hh" // stack.hh:132
template <class T, class S = std::vector<T> >
......@@ -151,8 +151,8 @@ namespace isc { namespace eval {
unsigned int range_;
};
#line 13 "parser.yy" // stack.hh:132
#line 14 "parser.yy" // stack.hh:132
} } // isc::eval
#line 156 "stack.hh" // stack.hh:132
#endif // !YY_YY_STACK_HH_INCLUDED
#endif // !YY_EVAL_STACK_HH_INCLUDED
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