2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-08 01:45:15 +00:00
Files
kea/src/lib/eval/parser.yy

76 lines
1.5 KiB
Plaintext
Raw Normal View History

2015-10-28 20:13:59 +01:00
%skeleton "lalr1.cc" /* -*- C++ -*- */
%require "3.0.2"
%defines
%define parser_class_name {EvalParser}
2015-10-28 20:13:59 +01:00
%define api.token.constructor
%define api.value.type variant
2015-10-28 20:53:40 +01:00
%define api.namespace {isc::eval}
2015-10-28 20:13:59 +01:00
%define parse.assert
%code requires
{
#include <string>
#include <eval/token.h>
class EvalContext;
using namespace isc::dhcp;
2015-10-28 20:13:59 +01:00
}
// The parsing context.
%param { EvalContext& ctx }
2015-10-28 20:13:59 +01:00
%locations
%initial-action
{
// Initialize the initial location.
@$.begin.filename = @$.end.filename = &ctx.file;
2015-10-28 20:13:59 +01:00
};
%define parse.trace
%define parse.error verbose
%code
{
# include "eval_context.h"
}
2015-10-28 20:53:40 +01:00
%define api.token.prefix {TOKEN_}
2015-10-28 20:13:59 +01:00
%token
END 0 "end of file"
EQUAL "=="
SUBSTRING "substring"
COMA ","
2015-10-28 20:13:59 +01:00
LPAREN "("
RPAREN ")"
;
%token <std::string> STRING "constant string"
%token <int> OPTION "option code"
2015-10-28 20:13:59 +01:00
%printer { yyoutput << $$; } <*>;
%%
// The whole grammar starts with an expression.
%start expression;
2015-10-28 20:13:59 +01:00
// Expression can either be a single token or a (something == something) expression
expression:
token EQUAL token {
TokenPtr eq(new TokenEqual());
ctx.expression.push_back(eq);
}
| token;
token:
STRING {
TokenPtr str(new TokenString($1));
ctx.expression.push_back(str);
}
| OPTION {
TokenPtr opt(new TokenOption($1));
ctx.expression.push_back(opt);
}
| SUBSTRING "(" token "," token "," token ")" {
/* push back TokenSubstring */
}
2015-10-28 20:13:59 +01:00
%%
void
2015-10-28 20:53:40 +01:00
isc::eval::EvalParser::error(const location_type& l,
const std::string& m)
2015-10-28 20:13:59 +01:00
{
ctx.error(l, m);
2015-10-28 20:13:59 +01:00
}