parser.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  1. // A Bison parser, made by GNU Bison 3.0.4.
  2. // Skeleton interface for Bison LALR(1) parsers in C++
  3. // Copyright (C) 2002-2015 Free Software Foundation, Inc.
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License
  13. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. // As a special exception, you may create a larger work that contains
  15. // part or all of the Bison parser skeleton and distribute that work
  16. // under terms of your choice, so long as that work isn't itself a
  17. // parser generator using the skeleton or a modified version thereof
  18. // as a parser skeleton. Alternatively, if you modify or redistribute
  19. // the parser skeleton itself, you may (at your option) remove this
  20. // special exception, which will cause the skeleton and the resulting
  21. // Bison output files to be licensed under the GNU General Public
  22. // License without this special exception.
  23. // This special exception was added by the Free Software Foundation in
  24. // version 2.2 of Bison.
  25. /**
  26. ** \file parser.h
  27. ** Define the isc::eval::parser class.
  28. */
  29. // C++ LALR(1) parser skeleton written by Akim Demaille.
  30. #ifndef YY_YY_PARSER_H_INCLUDED
  31. # define YY_YY_PARSER_H_INCLUDED
  32. // // "%code requires" blocks.
  33. #line 24 "parser.yy" // lalr1.cc:392
  34. #include <string>
  35. #include <eval/token.h>
  36. #include <eval/eval_context_decl.h>
  37. #include <dhcp/option.h>
  38. #include <boost/lexical_cast.hpp>
  39. using namespace isc::dhcp;
  40. using namespace isc::eval;
  41. #line 55 "parser.h" // lalr1.cc:392
  42. # include <cassert>
  43. # include <cstdlib> // std::abort
  44. # include <iostream>
  45. # include <stdexcept>
  46. # include <string>
  47. # include <vector>
  48. # include "stack.hh"
  49. # include "location.hh"
  50. #include <typeinfo>
  51. #ifndef YYASSERT
  52. # include <cassert>
  53. # define YYASSERT assert
  54. #endif
  55. #ifndef YY_ATTRIBUTE
  56. # if (defined __GNUC__ \
  57. && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
  58. || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
  59. # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
  60. # else
  61. # define YY_ATTRIBUTE(Spec) /* empty */
  62. # endif
  63. #endif
  64. #ifndef YY_ATTRIBUTE_PURE
  65. # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
  66. #endif
  67. #ifndef YY_ATTRIBUTE_UNUSED
  68. # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
  69. #endif
  70. #if !defined _Noreturn \
  71. && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
  72. # if defined _MSC_VER && 1200 <= _MSC_VER
  73. # define _Noreturn __declspec (noreturn)
  74. # else
  75. # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
  76. # endif
  77. #endif
  78. /* Suppress unused-variable warnings by "using" E. */
  79. #if ! defined lint || defined __GNUC__
  80. # define YYUSE(E) ((void) (E))
  81. #else
  82. # define YYUSE(E) /* empty */
  83. #endif
  84. #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
  85. /* Suppress an incorrect diagnostic about yylval being uninitialized. */
  86. # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
  87. _Pragma ("GCC diagnostic push") \
  88. _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
  89. _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
  90. # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
  91. _Pragma ("GCC diagnostic pop")
  92. #else
  93. # define YY_INITIAL_VALUE(Value) Value
  94. #endif
  95. #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  96. # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  97. # define YY_IGNORE_MAYBE_UNINITIALIZED_END
  98. #endif
  99. #ifndef YY_INITIAL_VALUE
  100. # define YY_INITIAL_VALUE(Value) /* Nothing. */
  101. #endif
  102. /* Debug traces. */
  103. #ifndef YYDEBUG
  104. # define YYDEBUG 1
  105. #endif
  106. #line 21 "parser.yy" // lalr1.cc:392
  107. namespace isc { namespace eval {
  108. #line 132 "parser.h" // lalr1.cc:392
  109. /// A char[S] buffer to store and retrieve objects.
  110. ///
  111. /// Sort of a variant, but does not keep track of the nature
  112. /// of the stored data, since that knowledge is available
  113. /// via the current state.
  114. template <size_t S>
  115. struct variant
  116. {
  117. /// Type of *this.
  118. typedef variant<S> self_type;
  119. /// Empty construction.
  120. variant ()
  121. : yytypeid_ (YY_NULLPTR)
  122. {}
  123. /// Construct and fill.
  124. template <typename T>
  125. variant (const T& t)
  126. : yytypeid_ (&typeid (T))
  127. {
  128. YYASSERT (sizeof (T) <= S);
  129. new (yyas_<T> ()) T (t);
  130. }
  131. /// Destruction, allowed only if empty.
  132. ~variant ()
  133. {
  134. YYASSERT (!yytypeid_);
  135. }
  136. /// Instantiate an empty \a T in here.
  137. template <typename T>
  138. T&
  139. build ()
  140. {
  141. YYASSERT (!yytypeid_);
  142. YYASSERT (sizeof (T) <= S);
  143. yytypeid_ = & typeid (T);
  144. return *new (yyas_<T> ()) T;
  145. }
  146. /// Instantiate a \a T in here from \a t.
  147. template <typename T>
  148. T&
  149. build (const T& t)
  150. {
  151. YYASSERT (!yytypeid_);
  152. YYASSERT (sizeof (T) <= S);
  153. yytypeid_ = & typeid (T);
  154. return *new (yyas_<T> ()) T (t);
  155. }
  156. /// Accessor to a built \a T.
  157. template <typename T>
  158. T&
  159. as ()
  160. {
  161. YYASSERT (*yytypeid_ == typeid (T));
  162. YYASSERT (sizeof (T) <= S);
  163. return *yyas_<T> ();
  164. }
  165. /// Const accessor to a built \a T (for %printer).
  166. template <typename T>
  167. const T&
  168. as () const
  169. {
  170. YYASSERT (*yytypeid_ == typeid (T));
  171. YYASSERT (sizeof (T) <= S);
  172. return *yyas_<T> ();
  173. }
  174. /// Swap the content with \a other, of same type.
  175. ///
  176. /// Both variants must be built beforehand, because swapping the actual
  177. /// data requires reading it (with as()), and this is not possible on
  178. /// unconstructed variants: it would require some dynamic testing, which
  179. /// should not be the variant's responsability.
  180. /// Swapping between built and (possibly) non-built is done with
  181. /// variant::move ().
  182. template <typename T>
  183. void
  184. swap (self_type& other)
  185. {
  186. YYASSERT (yytypeid_);
  187. YYASSERT (*yytypeid_ == *other.yytypeid_);
  188. std::swap (as<T> (), other.as<T> ());
  189. }
  190. /// Move the content of \a other to this.
  191. ///
  192. /// Destroys \a other.
  193. template <typename T>
  194. void
  195. move (self_type& other)
  196. {
  197. build<T> ();
  198. swap<T> (other);
  199. other.destroy<T> ();
  200. }
  201. /// Copy the content of \a other to this.
  202. template <typename T>
  203. void
  204. copy (const self_type& other)
  205. {
  206. build<T> (other.as<T> ());
  207. }
  208. /// Destroy the stored \a T.
  209. template <typename T>
  210. void
  211. destroy ()
  212. {
  213. as<T> ().~T ();
  214. yytypeid_ = YY_NULLPTR;
  215. }
  216. private:
  217. /// Prohibit blind copies.
  218. self_type& operator=(const self_type&);
  219. variant (const self_type&);
  220. /// Accessor to raw memory as \a T.
  221. template <typename T>
  222. T*
  223. yyas_ ()
  224. {
  225. void *yyp = yybuffer_.yyraw;
  226. return static_cast<T*> (yyp);
  227. }
  228. /// Const accessor to raw memory as \a T.
  229. template <typename T>
  230. const T*
  231. yyas_ () const
  232. {
  233. const void *yyp = yybuffer_.yyraw;
  234. return static_cast<const T*> (yyp);
  235. }
  236. union
  237. {
  238. /// Strongest alignment constraints.
  239. long double yyalign_me;
  240. /// A buffer large enough to store any of the semantic values.
  241. char yyraw[S];
  242. } yybuffer_;
  243. /// Whether the content is built: if defined, the name of the stored type.
  244. const std::type_info *yytypeid_;
  245. };
  246. /// A Bison parser.
  247. class EvalParser
  248. {
  249. public:
  250. #ifndef YYSTYPE
  251. /// An auxiliary type to compute the largest semantic type.
  252. union union_type
  253. {
  254. // option_repr_type
  255. char dummy1[sizeof(TokenOption::RepresentationType)];
  256. // "constant string"
  257. // "integer"
  258. // "constant hexstring"
  259. // "option name"
  260. // TOKEN
  261. char dummy2[sizeof(std::string)];
  262. // option_code
  263. char dummy3[sizeof(uint16_t)];
  264. };
  265. /// Symbol semantic values.
  266. typedef variant<sizeof(union_type)> semantic_type;
  267. #else
  268. typedef YYSTYPE semantic_type;
  269. #endif
  270. /// Symbol locations.
  271. typedef location location_type;
  272. /// Syntax errors thrown from user actions.
  273. struct syntax_error : std::runtime_error
  274. {
  275. syntax_error (const location_type& l, const std::string& m);
  276. location_type location;
  277. };
  278. /// Tokens.
  279. struct token
  280. {
  281. enum yytokentype
  282. {
  283. TOKEN_END = 0,
  284. TOKEN_EQUAL = 258,
  285. TOKEN_OPTION = 259,
  286. TOKEN_SUBSTRING = 260,
  287. TOKEN_NOT = 261,
  288. TOKEN_AND = 262,
  289. TOKEN_OR = 263,
  290. TOKEN_TEXT = 264,
  291. TOKEN_HEX = 265,
  292. TOKEN_EXISTS = 266,
  293. TOKEN_ALL = 267,
  294. TOKEN_DOT = 268,
  295. TOKEN_COMA = 269,
  296. TOKEN_LPAREN = 270,
  297. TOKEN_RPAREN = 271,
  298. TOKEN_LBRACKET = 272,
  299. TOKEN_RBRACKET = 273,
  300. TOKEN_STRING = 274,
  301. TOKEN_INTEGER = 275,
  302. TOKEN_HEXSTRING = 276,
  303. TOKEN_OPTION_NAME = 277,
  304. TOKEN_TOKEN = 278
  305. };
  306. };
  307. /// (External) token type, as returned by yylex.
  308. typedef token::yytokentype token_type;
  309. /// Symbol type: an internal symbol number.
  310. typedef int symbol_number_type;
  311. /// The symbol type number to denote an empty symbol.
  312. enum { empty_symbol = -2 };
  313. /// Internal symbol number for tokens (subsumed by symbol_number_type).
  314. typedef unsigned char token_number_type;
  315. /// A complete symbol.
  316. ///
  317. /// Expects its Base type to provide access to the symbol type
  318. /// via type_get().
  319. ///
  320. /// Provide access to semantic value and location.
  321. template <typename Base>
  322. struct basic_symbol : Base
  323. {
  324. /// Alias to Base.
  325. typedef Base super_type;
  326. /// Default constructor.
  327. basic_symbol ();
  328. /// Copy constructor.
  329. basic_symbol (const basic_symbol& other);
  330. /// Constructor for valueless symbols, and symbols from each type.
  331. basic_symbol (typename Base::kind_type t, const location_type& l);
  332. basic_symbol (typename Base::kind_type t, const TokenOption::RepresentationType v, const location_type& l);
  333. basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l);
  334. basic_symbol (typename Base::kind_type t, const uint16_t v, const location_type& l);
  335. /// Constructor for symbols with semantic value.
  336. basic_symbol (typename Base::kind_type t,
  337. const semantic_type& v,
  338. const location_type& l);
  339. /// Destroy the symbol.
  340. ~basic_symbol ();
  341. /// Destroy contents, and record that is empty.
  342. void clear ();
  343. /// Whether empty.
  344. bool empty () const;
  345. /// Destructive move, \a s is emptied into this.
  346. void move (basic_symbol& s);
  347. /// The semantic value.
  348. semantic_type value;
  349. /// The location.
  350. location_type location;
  351. private:
  352. /// Assignment operator.
  353. basic_symbol& operator= (const basic_symbol& other);
  354. };
  355. /// Type access provider for token (enum) based symbols.
  356. struct by_type
  357. {
  358. /// Default constructor.
  359. by_type ();
  360. /// Copy constructor.
  361. by_type (const by_type& other);
  362. /// The symbol type as needed by the constructor.
  363. typedef token_type kind_type;
  364. /// Constructor from (external) token numbers.
  365. by_type (kind_type t);
  366. /// Record that this symbol is empty.
  367. void clear ();
  368. /// Steal the symbol type from \a that.
  369. void move (by_type& that);
  370. /// The (internal) type number (corresponding to \a type).
  371. /// \a empty when empty.
  372. symbol_number_type type_get () const;
  373. /// The token.
  374. token_type token () const;
  375. /// The symbol type.
  376. /// \a empty_symbol when empty.
  377. /// An int, not token_number_type, to be able to store empty_symbol.
  378. int type;
  379. };
  380. /// "External" symbols: returned by the scanner.
  381. typedef basic_symbol<by_type> symbol_type;
  382. // Symbol constructors declarations.
  383. static inline
  384. symbol_type
  385. make_END (const location_type& l);
  386. static inline
  387. symbol_type
  388. make_EQUAL (const location_type& l);
  389. static inline
  390. symbol_type
  391. make_OPTION (const location_type& l);
  392. static inline
  393. symbol_type
  394. make_SUBSTRING (const location_type& l);
  395. static inline
  396. symbol_type
  397. make_NOT (const location_type& l);
  398. static inline
  399. symbol_type
  400. make_AND (const location_type& l);
  401. static inline
  402. symbol_type
  403. make_OR (const location_type& l);
  404. static inline
  405. symbol_type
  406. make_TEXT (const location_type& l);
  407. static inline
  408. symbol_type
  409. make_HEX (const location_type& l);
  410. static inline
  411. symbol_type
  412. make_EXISTS (const location_type& l);
  413. static inline
  414. symbol_type
  415. make_ALL (const location_type& l);
  416. static inline
  417. symbol_type
  418. make_DOT (const location_type& l);
  419. static inline
  420. symbol_type
  421. make_COMA (const location_type& l);
  422. static inline
  423. symbol_type
  424. make_LPAREN (const location_type& l);
  425. static inline
  426. symbol_type
  427. make_RPAREN (const location_type& l);
  428. static inline
  429. symbol_type
  430. make_LBRACKET (const location_type& l);
  431. static inline
  432. symbol_type
  433. make_RBRACKET (const location_type& l);
  434. static inline
  435. symbol_type
  436. make_STRING (const std::string& v, const location_type& l);
  437. static inline
  438. symbol_type
  439. make_INTEGER (const std::string& v, const location_type& l);
  440. static inline
  441. symbol_type
  442. make_HEXSTRING (const std::string& v, const location_type& l);
  443. static inline
  444. symbol_type
  445. make_OPTION_NAME (const std::string& v, const location_type& l);
  446. static inline
  447. symbol_type
  448. make_TOKEN (const std::string& v, const location_type& l);
  449. /// Build a parser object.
  450. EvalParser (EvalContext& ctx_yyarg);
  451. virtual ~EvalParser ();
  452. /// Parse.
  453. /// \returns 0 iff parsing succeeded.
  454. virtual int parse ();
  455. #if YYDEBUG
  456. /// The current debugging stream.
  457. std::ostream& debug_stream () const YY_ATTRIBUTE_PURE;
  458. /// Set the current debugging stream.
  459. void set_debug_stream (std::ostream &);
  460. /// Type for debugging levels.
  461. typedef int debug_level_type;
  462. /// The current debugging level.
  463. debug_level_type debug_level () const YY_ATTRIBUTE_PURE;
  464. /// Set the current debugging level.
  465. void set_debug_level (debug_level_type l);
  466. #endif
  467. /// Report a syntax error.
  468. /// \param loc where the syntax error is found.
  469. /// \param msg a description of the syntax error.
  470. virtual void error (const location_type& loc, const std::string& msg);
  471. /// Report a syntax error.
  472. void error (const syntax_error& err);
  473. private:
  474. /// This class is not copyable.
  475. EvalParser (const EvalParser&);
  476. EvalParser& operator= (const EvalParser&);
  477. /// State numbers.
  478. typedef int state_type;
  479. /// Generate an error message.
  480. /// \param yystate the state where the error occurred.
  481. /// \param yyla the lookahead token.
  482. virtual std::string yysyntax_error_ (state_type yystate,
  483. const symbol_type& yyla) const;
  484. /// Compute post-reduction state.
  485. /// \param yystate the current state
  486. /// \param yysym the nonterminal to push on the stack
  487. state_type yy_lr_goto_state_ (state_type yystate, int yysym);
  488. /// Whether the given \c yypact_ value indicates a defaulted state.
  489. /// \param yyvalue the value to check
  490. static bool yy_pact_value_is_default_ (int yyvalue);
  491. /// Whether the given \c yytable_ value indicates a syntax error.
  492. /// \param yyvalue the value to check
  493. static bool yy_table_value_is_error_ (int yyvalue);
  494. static const signed char yypact_ninf_;
  495. static const signed char yytable_ninf_;
  496. /// Convert a scanner token number \a t to a symbol number.
  497. static token_number_type yytranslate_ (token_type t);
  498. // Tables.
  499. // YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  500. // STATE-NUM.
  501. static const signed char yypact_[];
  502. // YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
  503. // Performed when YYTABLE does not specify something else to do. Zero
  504. // means the default is an error.
  505. static const unsigned char yydefact_[];
  506. // YYPGOTO[NTERM-NUM].
  507. static const signed char yypgoto_[];
  508. // YYDEFGOTO[NTERM-NUM].
  509. static const signed char yydefgoto_[];
  510. // YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
  511. // positive, shift that token. If negative, reduce the rule whose
  512. // number is the opposite. If YYTABLE_NINF, syntax error.
  513. static const unsigned char yytable_[];
  514. static const unsigned char yycheck_[];
  515. // YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  516. // symbol of state STATE-NUM.
  517. static const unsigned char yystos_[];
  518. // YYR1[YYN] -- Symbol number of symbol that rule YYN derives.
  519. static const unsigned char yyr1_[];
  520. // YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.
  521. static const unsigned char yyr2_[];
  522. /// Convert the symbol name \a n to a form suitable for a diagnostic.
  523. static std::string yytnamerr_ (const char *n);
  524. /// For a symbol, its name in clear.
  525. static const char* const yytname_[];
  526. #if YYDEBUG
  527. // YYRLINE[YYN] -- Source line where rule number YYN was defined.
  528. static const unsigned char yyrline_[];
  529. /// Report on the debug stream that the rule \a r is going to be reduced.
  530. virtual void yy_reduce_print_ (int r);
  531. /// Print the state stack on the debug stream.
  532. virtual void yystack_print_ ();
  533. // Debugging.
  534. int yydebug_;
  535. std::ostream* yycdebug_;
  536. /// \brief Display a symbol type, value and location.
  537. /// \param yyo The output stream.
  538. /// \param yysym The symbol.
  539. template <typename Base>
  540. void yy_print_ (std::ostream& yyo, const basic_symbol<Base>& yysym) const;
  541. #endif
  542. /// \brief Reclaim the memory associated to a symbol.
  543. /// \param yymsg Why this token is reclaimed.
  544. /// If null, print nothing.
  545. /// \param yysym The symbol.
  546. template <typename Base>
  547. void yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const;
  548. private:
  549. /// Type access provider for state based symbols.
  550. struct by_state
  551. {
  552. /// Default constructor.
  553. by_state ();
  554. /// The symbol type as needed by the constructor.
  555. typedef state_type kind_type;
  556. /// Constructor.
  557. by_state (kind_type s);
  558. /// Copy constructor.
  559. by_state (const by_state& other);
  560. /// Record that this symbol is empty.
  561. void clear ();
  562. /// Steal the symbol type from \a that.
  563. void move (by_state& that);
  564. /// The (internal) type number (corresponding to \a state).
  565. /// \a empty_symbol when empty.
  566. symbol_number_type type_get () const;
  567. /// The state number used to denote an empty symbol.
  568. enum { empty_state = -1 };
  569. /// The state.
  570. /// \a empty when empty.
  571. state_type state;
  572. };
  573. /// "Internal" symbol: element of the stack.
  574. struct stack_symbol_type : basic_symbol<by_state>
  575. {
  576. /// Superclass.
  577. typedef basic_symbol<by_state> super_type;
  578. /// Construct an empty symbol.
  579. stack_symbol_type ();
  580. /// Steal the contents from \a sym to build this.
  581. stack_symbol_type (state_type s, symbol_type& sym);
  582. /// Assignment, needed by push_back.
  583. stack_symbol_type& operator= (const stack_symbol_type& that);
  584. };
  585. /// Stack type.
  586. typedef stack<stack_symbol_type> stack_type;
  587. /// The stack.
  588. stack_type yystack_;
  589. /// Push a new state on the stack.
  590. /// \param m a debug message to display
  591. /// if null, no trace is output.
  592. /// \param s the symbol
  593. /// \warning the contents of \a s.value is stolen.
  594. void yypush_ (const char* m, stack_symbol_type& s);
  595. /// Push a new look ahead token on the state on the stack.
  596. /// \param m a debug message to display
  597. /// if null, no trace is output.
  598. /// \param s the state
  599. /// \param sym the symbol (for its value and location).
  600. /// \warning the contents of \a s.value is stolen.
  601. void yypush_ (const char* m, state_type s, symbol_type& sym);
  602. /// Pop \a n symbols the three stacks.
  603. void yypop_ (unsigned int n = 1);
  604. /// Constants.
  605. enum
  606. {
  607. yyeof_ = 0,
  608. yylast_ = 46, ///< Last index in yytable_.
  609. yynnts_ = 8, ///< Number of nonterminal symbols.
  610. yyfinal_ = 15, ///< Termination state number.
  611. yyterror_ = 1,
  612. yyerrcode_ = 256,
  613. yyntokens_ = 24 ///< Number of tokens.
  614. };
  615. // User arguments.
  616. EvalContext& ctx;
  617. };
  618. // Symbol number corresponding to token number t.
  619. inline
  620. EvalParser::token_number_type
  621. EvalParser::yytranslate_ (token_type t)
  622. {
  623. static
  624. const token_number_type
  625. translate_table[] =
  626. {
  627. 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  628. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  629. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  630. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  631. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  632. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  633. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  634. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  635. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  636. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  637. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  638. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  639. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  640. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  641. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  642. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  643. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  644. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  645. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  646. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  647. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  648. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  649. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  650. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  651. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  652. 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
  653. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  654. 15, 16, 17, 18, 19, 20, 21, 22, 23
  655. };
  656. const unsigned int user_token_number_max_ = 278;
  657. const token_number_type undef_token_ = 2;
  658. if (static_cast<int>(t) <= yyeof_)
  659. return yyeof_;
  660. else if (static_cast<unsigned int> (t) <= user_token_number_max_)
  661. return translate_table[t];
  662. else
  663. return undef_token_;
  664. }
  665. inline
  666. EvalParser::syntax_error::syntax_error (const location_type& l, const std::string& m)
  667. : std::runtime_error (m)
  668. , location (l)
  669. {}
  670. // basic_symbol.
  671. template <typename Base>
  672. inline
  673. EvalParser::basic_symbol<Base>::basic_symbol ()
  674. : value ()
  675. {}
  676. template <typename Base>
  677. inline
  678. EvalParser::basic_symbol<Base>::basic_symbol (const basic_symbol& other)
  679. : Base (other)
  680. , value ()
  681. , location (other.location)
  682. {
  683. switch (other.type_get ())
  684. {
  685. case 29: // option_repr_type
  686. value.copy< TokenOption::RepresentationType > (other.value);
  687. break;
  688. case 19: // "constant string"
  689. case 20: // "integer"
  690. case 21: // "constant hexstring"
  691. case 22: // "option name"
  692. case 23: // TOKEN
  693. value.copy< std::string > (other.value);
  694. break;
  695. case 28: // option_code
  696. value.copy< uint16_t > (other.value);
  697. break;
  698. default:
  699. break;
  700. }
  701. }
  702. template <typename Base>
  703. inline
  704. EvalParser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const semantic_type& v, const location_type& l)
  705. : Base (t)
  706. , value ()
  707. , location (l)
  708. {
  709. (void) v;
  710. switch (this->type_get ())
  711. {
  712. case 29: // option_repr_type
  713. value.copy< TokenOption::RepresentationType > (v);
  714. break;
  715. case 19: // "constant string"
  716. case 20: // "integer"
  717. case 21: // "constant hexstring"
  718. case 22: // "option name"
  719. case 23: // TOKEN
  720. value.copy< std::string > (v);
  721. break;
  722. case 28: // option_code
  723. value.copy< uint16_t > (v);
  724. break;
  725. default:
  726. break;
  727. }
  728. }
  729. // Implementation of basic_symbol constructor for each type.
  730. template <typename Base>
  731. EvalParser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const location_type& l)
  732. : Base (t)
  733. , value ()
  734. , location (l)
  735. {}
  736. template <typename Base>
  737. EvalParser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const TokenOption::RepresentationType v, const location_type& l)
  738. : Base (t)
  739. , value (v)
  740. , location (l)
  741. {}
  742. template <typename Base>
  743. EvalParser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l)
  744. : Base (t)
  745. , value (v)
  746. , location (l)
  747. {}
  748. template <typename Base>
  749. EvalParser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const uint16_t v, const location_type& l)
  750. : Base (t)
  751. , value (v)
  752. , location (l)
  753. {}
  754. template <typename Base>
  755. inline
  756. EvalParser::basic_symbol<Base>::~basic_symbol ()
  757. {
  758. clear ();
  759. }
  760. template <typename Base>
  761. inline
  762. void
  763. EvalParser::basic_symbol<Base>::clear ()
  764. {
  765. // User destructor.
  766. symbol_number_type yytype = this->type_get ();
  767. basic_symbol<Base>& yysym = *this;
  768. (void) yysym;
  769. switch (yytype)
  770. {
  771. default:
  772. break;
  773. }
  774. // Type destructor.
  775. switch (yytype)
  776. {
  777. case 29: // option_repr_type
  778. value.template destroy< TokenOption::RepresentationType > ();
  779. break;
  780. case 19: // "constant string"
  781. case 20: // "integer"
  782. case 21: // "constant hexstring"
  783. case 22: // "option name"
  784. case 23: // TOKEN
  785. value.template destroy< std::string > ();
  786. break;
  787. case 28: // option_code
  788. value.template destroy< uint16_t > ();
  789. break;
  790. default:
  791. break;
  792. }
  793. Base::clear ();
  794. }
  795. template <typename Base>
  796. inline
  797. bool
  798. EvalParser::basic_symbol<Base>::empty () const
  799. {
  800. return Base::type_get () == empty_symbol;
  801. }
  802. template <typename Base>
  803. inline
  804. void
  805. EvalParser::basic_symbol<Base>::move (basic_symbol& s)
  806. {
  807. super_type::move(s);
  808. switch (this->type_get ())
  809. {
  810. case 29: // option_repr_type
  811. value.move< TokenOption::RepresentationType > (s.value);
  812. break;
  813. case 19: // "constant string"
  814. case 20: // "integer"
  815. case 21: // "constant hexstring"
  816. case 22: // "option name"
  817. case 23: // TOKEN
  818. value.move< std::string > (s.value);
  819. break;
  820. case 28: // option_code
  821. value.move< uint16_t > (s.value);
  822. break;
  823. default:
  824. break;
  825. }
  826. location = s.location;
  827. }
  828. // by_type.
  829. inline
  830. EvalParser::by_type::by_type ()
  831. : type (empty_symbol)
  832. {}
  833. inline
  834. EvalParser::by_type::by_type (const by_type& other)
  835. : type (other.type)
  836. {}
  837. inline
  838. EvalParser::by_type::by_type (token_type t)
  839. : type (yytranslate_ (t))
  840. {}
  841. inline
  842. void
  843. EvalParser::by_type::clear ()
  844. {
  845. type = empty_symbol;
  846. }
  847. inline
  848. void
  849. EvalParser::by_type::move (by_type& that)
  850. {
  851. type = that.type;
  852. that.clear ();
  853. }
  854. inline
  855. int
  856. EvalParser::by_type::type_get () const
  857. {
  858. return type;
  859. }
  860. inline
  861. EvalParser::token_type
  862. EvalParser::by_type::token () const
  863. {
  864. // YYTOKNUM[NUM] -- (External) token number corresponding to the
  865. // (internal) symbol number NUM (which must be that of a token). */
  866. static
  867. const unsigned short int
  868. yytoken_number_[] =
  869. {
  870. 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
  871. 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
  872. 275, 276, 277, 278
  873. };
  874. return static_cast<token_type> (yytoken_number_[type]);
  875. }
  876. // Implementation of make_symbol for each symbol type.
  877. EvalParser::symbol_type
  878. EvalParser::make_END (const location_type& l)
  879. {
  880. return symbol_type (token::TOKEN_END, l);
  881. }
  882. EvalParser::symbol_type
  883. EvalParser::make_EQUAL (const location_type& l)
  884. {
  885. return symbol_type (token::TOKEN_EQUAL, l);
  886. }
  887. EvalParser::symbol_type
  888. EvalParser::make_OPTION (const location_type& l)
  889. {
  890. return symbol_type (token::TOKEN_OPTION, l);
  891. }
  892. EvalParser::symbol_type
  893. EvalParser::make_SUBSTRING (const location_type& l)
  894. {
  895. return symbol_type (token::TOKEN_SUBSTRING, l);
  896. }
  897. EvalParser::symbol_type
  898. EvalParser::make_NOT (const location_type& l)
  899. {
  900. return symbol_type (token::TOKEN_NOT, l);
  901. }
  902. EvalParser::symbol_type
  903. EvalParser::make_AND (const location_type& l)
  904. {
  905. return symbol_type (token::TOKEN_AND, l);
  906. }
  907. EvalParser::symbol_type
  908. EvalParser::make_OR (const location_type& l)
  909. {
  910. return symbol_type (token::TOKEN_OR, l);
  911. }
  912. EvalParser::symbol_type
  913. EvalParser::make_TEXT (const location_type& l)
  914. {
  915. return symbol_type (token::TOKEN_TEXT, l);
  916. }
  917. EvalParser::symbol_type
  918. EvalParser::make_HEX (const location_type& l)
  919. {
  920. return symbol_type (token::TOKEN_HEX, l);
  921. }
  922. EvalParser::symbol_type
  923. EvalParser::make_EXISTS (const location_type& l)
  924. {
  925. return symbol_type (token::TOKEN_EXISTS, l);
  926. }
  927. EvalParser::symbol_type
  928. EvalParser::make_ALL (const location_type& l)
  929. {
  930. return symbol_type (token::TOKEN_ALL, l);
  931. }
  932. EvalParser::symbol_type
  933. EvalParser::make_DOT (const location_type& l)
  934. {
  935. return symbol_type (token::TOKEN_DOT, l);
  936. }
  937. EvalParser::symbol_type
  938. EvalParser::make_COMA (const location_type& l)
  939. {
  940. return symbol_type (token::TOKEN_COMA, l);
  941. }
  942. EvalParser::symbol_type
  943. EvalParser::make_LPAREN (const location_type& l)
  944. {
  945. return symbol_type (token::TOKEN_LPAREN, l);
  946. }
  947. EvalParser::symbol_type
  948. EvalParser::make_RPAREN (const location_type& l)
  949. {
  950. return symbol_type (token::TOKEN_RPAREN, l);
  951. }
  952. EvalParser::symbol_type
  953. EvalParser::make_LBRACKET (const location_type& l)
  954. {
  955. return symbol_type (token::TOKEN_LBRACKET, l);
  956. }
  957. EvalParser::symbol_type
  958. EvalParser::make_RBRACKET (const location_type& l)
  959. {
  960. return symbol_type (token::TOKEN_RBRACKET, l);
  961. }
  962. EvalParser::symbol_type
  963. EvalParser::make_STRING (const std::string& v, const location_type& l)
  964. {
  965. return symbol_type (token::TOKEN_STRING, v, l);
  966. }
  967. EvalParser::symbol_type
  968. EvalParser::make_INTEGER (const std::string& v, const location_type& l)
  969. {
  970. return symbol_type (token::TOKEN_INTEGER, v, l);
  971. }
  972. EvalParser::symbol_type
  973. EvalParser::make_HEXSTRING (const std::string& v, const location_type& l)
  974. {
  975. return symbol_type (token::TOKEN_HEXSTRING, v, l);
  976. }
  977. EvalParser::symbol_type
  978. EvalParser::make_OPTION_NAME (const std::string& v, const location_type& l)
  979. {
  980. return symbol_type (token::TOKEN_OPTION_NAME, v, l);
  981. }
  982. EvalParser::symbol_type
  983. EvalParser::make_TOKEN (const std::string& v, const location_type& l)
  984. {
  985. return symbol_type (token::TOKEN_TOKEN, v, l);
  986. }
  987. #line 21 "parser.yy" // lalr1.cc:392
  988. } } // isc::eval
  989. #line 1205 "parser.h" // lalr1.cc:392
  990. #endif // !YY_YY_PARSER_H_INCLUDED