parser.h 28 KB

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