mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 06:25:34 +00:00
[4088] Classes renamed to Kea nomenclature
This commit is contained in:
@@ -1,38 +1,51 @@
|
|||||||
#line 11104 "./doc/bison.texi"
|
|
||||||
#include "eval_context.h"
|
#include "eval_context.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
calcxx_driver::calcxx_driver ()
|
#include <fstream>
|
||||||
|
|
||||||
|
EvalContext::EvalContext ()
|
||||||
: trace_scanning (false), trace_parsing (false)
|
: trace_scanning (false), trace_parsing (false)
|
||||||
{
|
{
|
||||||
variables["one"] = 1;
|
variables["one"] = 1;
|
||||||
variables["two"] = 2;
|
variables["two"] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
calcxx_driver::~calcxx_driver ()
|
EvalContext::~EvalContext ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
calcxx_driver::parse (const std::string &f)
|
EvalContext::parseFile(const std::string &filename)
|
||||||
{
|
{
|
||||||
file = f;
|
file = filename;
|
||||||
scan_begin ();
|
scan_begin();
|
||||||
yy::calcxx_parser parser (*this);
|
yy::EvalParser parser (*this);
|
||||||
parser.set_debug_level (trace_parsing);
|
parser.set_debug_level(trace_parsing);
|
||||||
int res = parser.parse ();
|
int res = parser.parse();
|
||||||
scan_end ();
|
scan_end();
|
||||||
return res;
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
EvalContext::parseString(const std::string& str)
|
||||||
|
{
|
||||||
|
remove("/tmp/eval");
|
||||||
|
std::fstream f("/tmp/eval", std::ios::trunc);
|
||||||
|
|
||||||
|
f << str;
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
return (parseFile("/tmp/eval"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
calcxx_driver::error (const yy::location& l, const std::string& m)
|
EvalContext::error (const yy::location& l, const std::string& m)
|
||||||
{
|
{
|
||||||
std::cerr << l << ": " << m << std::endl;
|
std::cerr << l << ": " << m << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
calcxx_driver::error (const std::string& m)
|
EvalContext::error (const std::string& m)
|
||||||
{
|
{
|
||||||
std::cerr << m << std::endl;
|
std::cerr << m << std::endl;
|
||||||
}
|
}
|
||||||
|
@@ -1,22 +1,22 @@
|
|||||||
#ifndef CALCXX_DRIVER_HH
|
#ifndef EVAL_CONTEXT_H
|
||||||
# define CALCXX_DRIVER_HH
|
#define EVAL_CONTEXT_H
|
||||||
# include <string>
|
# include <string>
|
||||||
# include <map>
|
# include <map>
|
||||||
# include "parser.h"
|
# include "parser.h"
|
||||||
|
|
||||||
// Tell Flex the lexer's prototype ...
|
// Tell Flex the lexer's prototype ...
|
||||||
# define YY_DECL \
|
# define YY_DECL \
|
||||||
yy::calcxx_parser::symbol_type yylex (calcxx_driver& driver)
|
yy::EvalParser::symbol_type yylex (EvalContext& driver)
|
||||||
|
|
||||||
// ... and declare it for the parser's sake.
|
// ... and declare it for the parser's sake.
|
||||||
YY_DECL;
|
YY_DECL;
|
||||||
|
|
||||||
// Conducting the whole scanning and parsing of Calc++.
|
// Conducting the whole scanning and parsing of Calc++.
|
||||||
class calcxx_driver
|
class EvalContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
calcxx_driver ();
|
EvalContext ();
|
||||||
virtual ~calcxx_driver ();
|
virtual ~EvalContext ();
|
||||||
|
|
||||||
std::map<std::string, int> variables;
|
std::map<std::string, int> variables;
|
||||||
|
|
||||||
@@ -29,7 +29,9 @@ public:
|
|||||||
|
|
||||||
// Run the parser on file F.
|
// Run the parser on file F.
|
||||||
// Return 0 on success.
|
// Return 0 on success.
|
||||||
int parse (const std::string& f);
|
int parseFile(const std::string& filename);
|
||||||
|
|
||||||
|
int parseString(const std::string& str);
|
||||||
|
|
||||||
// The name of the file being parsed.
|
// The name of the file being parsed.
|
||||||
// Used later to pass the file name to the location tracker.
|
// Used later to pass the file name to the location tracker.
|
||||||
@@ -42,4 +44,4 @@ public:
|
|||||||
void error (const yy::location& l, const std::string& m);
|
void error (const yy::location& l, const std::string& m);
|
||||||
void error (const std::string& m);
|
void error (const std::string& m);
|
||||||
};
|
};
|
||||||
#endif // ! CALCXX_DRIVER_HH
|
#endif // ! EVALCONTEXT_HH
|
||||||
|
@@ -22,26 +22,26 @@ int [0-9]+
|
|||||||
blank [ \t]
|
blank [ \t]
|
||||||
|
|
||||||
%{
|
%{
|
||||||
// Code run each time a pattern is matched.
|
// Code run each time a pattern is matched.
|
||||||
# define YY_USER_ACTION loc.columns (yyleng);
|
#define YY_USER_ACTION loc.columns(yyleng);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
%{
|
%{
|
||||||
// Code run each time yylex is called.
|
// Code run each time yylex is called.
|
||||||
loc.step ();
|
loc.step();
|
||||||
%}
|
%}
|
||||||
|
|
||||||
{blank}+ loc.step ();
|
{blank}+ loc.step ();
|
||||||
[\n]+ loc.lines (yyleng); loc.step ();
|
[\n]+ loc.lines (yyleng); loc.step ();
|
||||||
"-" return yy::calcxx_parser::make_MINUS(loc);
|
"-" return yy::EvalParser::make_MINUS(loc);
|
||||||
"+" return yy::calcxx_parser::make_PLUS(loc);
|
"+" return yy::EvalParser::make_PLUS(loc);
|
||||||
"*" return yy::calcxx_parser::make_STAR(loc);
|
"*" return yy::EvalParser::make_STAR(loc);
|
||||||
"/" return yy::calcxx_parser::make_SLASH(loc);
|
"/" return yy::EvalParser::make_SLASH(loc);
|
||||||
"(" return yy::calcxx_parser::make_LPAREN(loc);
|
"(" return yy::EvalParser::make_LPAREN(loc);
|
||||||
")" return yy::calcxx_parser::make_RPAREN(loc);
|
")" return yy::EvalParser::make_RPAREN(loc);
|
||||||
":=" return yy::calcxx_parser::make_ASSIGN(loc);
|
":=" return yy::EvalParser::make_ASSIGN(loc);
|
||||||
|
|
||||||
|
|
||||||
{int} {
|
{int} {
|
||||||
@@ -49,31 +49,29 @@ blank [ \t]
|
|||||||
long n = strtol (yytext, NULL, 10);
|
long n = strtol (yytext, NULL, 10);
|
||||||
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
|
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
|
||||||
driver.error (loc, "integer is out of range");
|
driver.error (loc, "integer is out of range");
|
||||||
return yy::calcxx_parser::make_NUMBER(n, loc);
|
return yy::EvalParser::make_NUMBER(n, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
{id} return yy::calcxx_parser::make_IDENTIFIER(yytext, loc);
|
{id} return yy::EvalParser::make_IDENTIFIER(yytext, loc);
|
||||||
. driver.error (loc, "invalid character");
|
. driver.error (loc, "invalid character");
|
||||||
<<EOF>> return yy::calcxx_parser::make_END(loc);
|
<<EOF>> return yy::EvalParser::make_END(loc);
|
||||||
%%
|
%%
|
||||||
|
|
||||||
void
|
void
|
||||||
calcxx_driver::scan_begin ()
|
EvalContext::scan_begin()
|
||||||
{
|
{
|
||||||
yy_flex_debug = trace_scanning;
|
yy_flex_debug = trace_scanning;
|
||||||
if (file.empty () || file == "-")
|
if (file.empty () || file == "-")
|
||||||
yyin = stdin;
|
yyin = stdin;
|
||||||
else if (!(yyin = fopen (file.c_str (), "r")))
|
else if (!(yyin = fopen(file.c_str (), "r")))
|
||||||
{
|
{
|
||||||
error ("cannot open " + file + ": " + strerror(errno));
|
error ("cannot open " + file + ": " + strerror(errno));
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
calcxx_driver::scan_end ()
|
EvalContext::scan_end()
|
||||||
{
|
{
|
||||||
fclose (yyin);
|
fclose (yyin);
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,17 @@
|
|||||||
%skeleton "lalr1.cc" /* -*- C++ -*- */
|
%skeleton "lalr1.cc" /* -*- C++ -*- */
|
||||||
%require "3.0.2"
|
%require "3.0.2"
|
||||||
%defines
|
%defines
|
||||||
%define parser_class_name {calcxx_parser}
|
%define parser_class_name {EvalParser}
|
||||||
%define api.token.constructor
|
%define api.token.constructor
|
||||||
%define api.value.type variant
|
%define api.value.type variant
|
||||||
%define parse.assert
|
%define parse.assert
|
||||||
%code requires
|
%code requires
|
||||||
{
|
{
|
||||||
# include <string>
|
# include <string>
|
||||||
class calcxx_driver;
|
class EvalContext;
|
||||||
}
|
}
|
||||||
// The parsing context.
|
// The parsing context.
|
||||||
%param { calcxx_driver& driver }
|
%param { EvalContext& driver }
|
||||||
%locations
|
%locations
|
||||||
%initial-action
|
%initial-action
|
||||||
{
|
{
|
||||||
@@ -62,8 +62,8 @@ exp:
|
|||||||
| "number" { std::swap ($$, $1); };
|
| "number" { std::swap ($$, $1); };
|
||||||
%%
|
%%
|
||||||
void
|
void
|
||||||
yy::calcxx_parser::error (const location_type& l,
|
yy::EvalParser::error(const location_type& l,
|
||||||
const std::string& m)
|
const std::string& m)
|
||||||
{
|
{
|
||||||
driver.error (l, m);
|
driver.error (l, m);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user