parser.cc 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  1. // A Bison parser, made by GNU Bison 3.0.4.
  2. // Skeleton implementation 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. // First part of user declarations.
  26. #line 37 "parser.cc" // lalr1.cc:404
  27. # ifndef YY_NULLPTR
  28. # if defined __cplusplus && 201103L <= __cplusplus
  29. # define YY_NULLPTR nullptr
  30. # else
  31. # define YY_NULLPTR 0
  32. # endif
  33. # endif
  34. #include "parser.h"
  35. // User implementation prologue.
  36. #line 51 "parser.cc" // lalr1.cc:412
  37. // Unqualified %code blocks.
  38. #line 39 "parser.yy" // lalr1.cc:413
  39. # include "eval_context.h"
  40. #line 67 "parser.yy" // lalr1.cc:413
  41. namespace {
  42. /* Convert option code specified as string to an 16 bit unsigned
  43. representation. If the option code is not within the range of
  44. 0..65535 an error is reported. */
  45. uint16_t
  46. convert_option_code(const std::string& option_code,
  47. const isc::eval::EvalParser::location_type& loc,
  48. EvalContext& ctx) {
  49. int n = 0;
  50. try {
  51. n = boost::lexical_cast<int>(option_code);
  52. } catch (const boost::bad_lexical_cast &) {
  53. // This can't happen...
  54. ctx.error(loc, "Option code has invalid value in " + option_code);
  55. }
  56. if (n < 0 || n > 65535) {
  57. ctx.error(loc, "Option code has invalid value in "
  58. + option_code + ". Allowed range: 0..65535");
  59. }
  60. return (static_cast<uint16_t>(n));
  61. }
  62. }
  63. #line 83 "parser.cc" // lalr1.cc:413
  64. #ifndef YY_
  65. # if defined YYENABLE_NLS && YYENABLE_NLS
  66. # if ENABLE_NLS
  67. # include <libintl.h> // FIXME: INFRINGES ON USER NAME SPACE.
  68. # define YY_(msgid) dgettext ("bison-runtime", msgid)
  69. # endif
  70. # endif
  71. # ifndef YY_
  72. # define YY_(msgid) msgid
  73. # endif
  74. #endif
  75. #define YYRHSLOC(Rhs, K) ((Rhs)[K].location)
  76. /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  77. If N is 0, then set CURRENT to the empty location which ends
  78. the previous symbol: RHS[0] (always defined). */
  79. # ifndef YYLLOC_DEFAULT
  80. # define YYLLOC_DEFAULT(Current, Rhs, N) \
  81. do \
  82. if (N) \
  83. { \
  84. (Current).begin = YYRHSLOC (Rhs, 1).begin; \
  85. (Current).end = YYRHSLOC (Rhs, N).end; \
  86. } \
  87. else \
  88. { \
  89. (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
  90. } \
  91. while (/*CONSTCOND*/ false)
  92. # endif
  93. // Suppress unused-variable warnings by "using" E.
  94. #define YYUSE(E) ((void) (E))
  95. // Enable debugging if requested.
  96. #if YYDEBUG
  97. // A pseudo ostream that takes yydebug_ into account.
  98. # define YYCDEBUG if (yydebug_) (*yycdebug_)
  99. # define YY_SYMBOL_PRINT(Title, Symbol) \
  100. do { \
  101. if (yydebug_) \
  102. { \
  103. *yycdebug_ << Title << ' '; \
  104. yy_print_ (*yycdebug_, Symbol); \
  105. *yycdebug_ << std::endl; \
  106. } \
  107. } while (false)
  108. # define YY_REDUCE_PRINT(Rule) \
  109. do { \
  110. if (yydebug_) \
  111. yy_reduce_print_ (Rule); \
  112. } while (false)
  113. # define YY_STACK_PRINT() \
  114. do { \
  115. if (yydebug_) \
  116. yystack_print_ (); \
  117. } while (false)
  118. #else // !YYDEBUG
  119. # define YYCDEBUG if (false) std::cerr
  120. # define YY_SYMBOL_PRINT(Title, Symbol) YYUSE(Symbol)
  121. # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
  122. # define YY_STACK_PRINT() static_cast<void>(0)
  123. #endif // !YYDEBUG
  124. #define yyerrok (yyerrstatus_ = 0)
  125. #define yyclearin (yyla.clear ())
  126. #define YYACCEPT goto yyacceptlab
  127. #define YYABORT goto yyabortlab
  128. #define YYERROR goto yyerrorlab
  129. #define YYRECOVERING() (!!yyerrstatus_)
  130. #line 21 "parser.yy" // lalr1.cc:479
  131. namespace isc { namespace eval {
  132. #line 169 "parser.cc" // lalr1.cc:479
  133. /* Return YYSTR after stripping away unnecessary quotes and
  134. backslashes, so that it's suitable for yyerror. The heuristic is
  135. that double-quoting is unnecessary unless the string contains an
  136. apostrophe, a comma, or backslash (other than backslash-backslash).
  137. YYSTR is taken from yytname. */
  138. std::string
  139. EvalParser::yytnamerr_ (const char *yystr)
  140. {
  141. if (*yystr == '"')
  142. {
  143. std::string yyr = "";
  144. char const *yyp = yystr;
  145. for (;;)
  146. switch (*++yyp)
  147. {
  148. case '\'':
  149. case ',':
  150. goto do_not_strip_quotes;
  151. case '\\':
  152. if (*++yyp != '\\')
  153. goto do_not_strip_quotes;
  154. // Fall through.
  155. default:
  156. yyr += *yyp;
  157. break;
  158. case '"':
  159. return yyr;
  160. }
  161. do_not_strip_quotes: ;
  162. }
  163. return yystr;
  164. }
  165. /// Build a parser object.
  166. EvalParser::EvalParser (EvalContext& ctx_yyarg)
  167. :
  168. #if YYDEBUG
  169. yydebug_ (false),
  170. yycdebug_ (&std::cerr),
  171. #endif
  172. ctx (ctx_yyarg)
  173. {}
  174. EvalParser::~EvalParser ()
  175. {}
  176. /*---------------.
  177. | Symbol types. |
  178. `---------------*/
  179. // by_state.
  180. inline
  181. EvalParser::by_state::by_state ()
  182. : state (empty_state)
  183. {}
  184. inline
  185. EvalParser::by_state::by_state (const by_state& other)
  186. : state (other.state)
  187. {}
  188. inline
  189. void
  190. EvalParser::by_state::clear ()
  191. {
  192. state = empty_state;
  193. }
  194. inline
  195. void
  196. EvalParser::by_state::move (by_state& that)
  197. {
  198. state = that.state;
  199. that.clear ();
  200. }
  201. inline
  202. EvalParser::by_state::by_state (state_type s)
  203. : state (s)
  204. {}
  205. inline
  206. EvalParser::symbol_number_type
  207. EvalParser::by_state::type_get () const
  208. {
  209. if (state == empty_state)
  210. return empty_symbol;
  211. else
  212. return yystos_[state];
  213. }
  214. inline
  215. EvalParser::stack_symbol_type::stack_symbol_type ()
  216. {}
  217. inline
  218. EvalParser::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that)
  219. : super_type (s, that.location)
  220. {
  221. switch (that.type_get ())
  222. {
  223. case 15: // "constant string"
  224. case 16: // "integer"
  225. case 17: // "constant hexstring"
  226. case 18: // TOKEN
  227. value.move< std::string > (that.value);
  228. break;
  229. default:
  230. break;
  231. }
  232. // that is emptied.
  233. that.type = empty_symbol;
  234. }
  235. inline
  236. EvalParser::stack_symbol_type&
  237. EvalParser::stack_symbol_type::operator= (const stack_symbol_type& that)
  238. {
  239. state = that.state;
  240. switch (that.type_get ())
  241. {
  242. case 15: // "constant string"
  243. case 16: // "integer"
  244. case 17: // "constant hexstring"
  245. case 18: // TOKEN
  246. value.copy< std::string > (that.value);
  247. break;
  248. default:
  249. break;
  250. }
  251. location = that.location;
  252. return *this;
  253. }
  254. template <typename Base>
  255. inline
  256. void
  257. EvalParser::yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const
  258. {
  259. if (yymsg)
  260. YY_SYMBOL_PRINT (yymsg, yysym);
  261. }
  262. #if YYDEBUG
  263. template <typename Base>
  264. void
  265. EvalParser::yy_print_ (std::ostream& yyo,
  266. const basic_symbol<Base>& yysym) const
  267. {
  268. std::ostream& yyoutput = yyo;
  269. YYUSE (yyoutput);
  270. symbol_number_type yytype = yysym.type_get ();
  271. // Avoid a (spurious) G++ 4.8 warning about "array subscript is
  272. // below array bounds".
  273. if (yysym.empty ())
  274. std::abort ();
  275. yyo << (yytype < yyntokens_ ? "token" : "nterm")
  276. << ' ' << yytname_[yytype] << " ("
  277. << yysym.location << ": ";
  278. switch (yytype)
  279. {
  280. case 15: // "constant string"
  281. #line 64 "parser.yy" // lalr1.cc:636
  282. { yyoutput << yysym.value.template as< std::string > (); }
  283. #line 350 "parser.cc" // lalr1.cc:636
  284. break;
  285. case 16: // "integer"
  286. #line 64 "parser.yy" // lalr1.cc:636
  287. { yyoutput << yysym.value.template as< std::string > (); }
  288. #line 357 "parser.cc" // lalr1.cc:636
  289. break;
  290. case 17: // "constant hexstring"
  291. #line 64 "parser.yy" // lalr1.cc:636
  292. { yyoutput << yysym.value.template as< std::string > (); }
  293. #line 364 "parser.cc" // lalr1.cc:636
  294. break;
  295. case 18: // TOKEN
  296. #line 64 "parser.yy" // lalr1.cc:636
  297. { yyoutput << yysym.value.template as< std::string > (); }
  298. #line 371 "parser.cc" // lalr1.cc:636
  299. break;
  300. default:
  301. break;
  302. }
  303. yyo << ')';
  304. }
  305. #endif
  306. inline
  307. void
  308. EvalParser::yypush_ (const char* m, state_type s, symbol_type& sym)
  309. {
  310. stack_symbol_type t (s, sym);
  311. yypush_ (m, t);
  312. }
  313. inline
  314. void
  315. EvalParser::yypush_ (const char* m, stack_symbol_type& s)
  316. {
  317. if (m)
  318. YY_SYMBOL_PRINT (m, s);
  319. yystack_.push (s);
  320. }
  321. inline
  322. void
  323. EvalParser::yypop_ (unsigned int n)
  324. {
  325. yystack_.pop (n);
  326. }
  327. #if YYDEBUG
  328. std::ostream&
  329. EvalParser::debug_stream () const
  330. {
  331. return *yycdebug_;
  332. }
  333. void
  334. EvalParser::set_debug_stream (std::ostream& o)
  335. {
  336. yycdebug_ = &o;
  337. }
  338. EvalParser::debug_level_type
  339. EvalParser::debug_level () const
  340. {
  341. return yydebug_;
  342. }
  343. void
  344. EvalParser::set_debug_level (debug_level_type l)
  345. {
  346. yydebug_ = l;
  347. }
  348. #endif // YYDEBUG
  349. inline EvalParser::state_type
  350. EvalParser::yy_lr_goto_state_ (state_type yystate, int yysym)
  351. {
  352. int yyr = yypgoto_[yysym - yyntokens_] + yystate;
  353. if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
  354. return yytable_[yyr];
  355. else
  356. return yydefgoto_[yysym - yyntokens_];
  357. }
  358. inline bool
  359. EvalParser::yy_pact_value_is_default_ (int yyvalue)
  360. {
  361. return yyvalue == yypact_ninf_;
  362. }
  363. inline bool
  364. EvalParser::yy_table_value_is_error_ (int yyvalue)
  365. {
  366. return yyvalue == yytable_ninf_;
  367. }
  368. int
  369. EvalParser::parse ()
  370. {
  371. // State.
  372. int yyn;
  373. /// Length of the RHS of the rule being reduced.
  374. int yylen = 0;
  375. // Error handling.
  376. int yynerrs_ = 0;
  377. int yyerrstatus_ = 0;
  378. /// The lookahead symbol.
  379. symbol_type yyla;
  380. /// The locations where the error started and ended.
  381. stack_symbol_type yyerror_range[3];
  382. /// The return value of parse ().
  383. int yyresult;
  384. // FIXME: This shoud be completely indented. It is not yet to
  385. // avoid gratuitous conflicts when merging into the master branch.
  386. try
  387. {
  388. YYCDEBUG << "Starting parse" << std::endl;
  389. /* Initialize the stack. The initial state will be set in
  390. yynewstate, since the latter expects the semantical and the
  391. location values to have been already stored, initialize these
  392. stacks with a primary value. */
  393. yystack_.clear ();
  394. yypush_ (YY_NULLPTR, 0, yyla);
  395. // A new symbol was pushed on the stack.
  396. yynewstate:
  397. YYCDEBUG << "Entering state " << yystack_[0].state << std::endl;
  398. // Accept?
  399. if (yystack_[0].state == yyfinal_)
  400. goto yyacceptlab;
  401. goto yybackup;
  402. // Backup.
  403. yybackup:
  404. // Try to take a decision without lookahead.
  405. yyn = yypact_[yystack_[0].state];
  406. if (yy_pact_value_is_default_ (yyn))
  407. goto yydefault;
  408. // Read a lookahead token.
  409. if (yyla.empty ())
  410. {
  411. YYCDEBUG << "Reading a token: ";
  412. try
  413. {
  414. symbol_type yylookahead (yylex (ctx));
  415. yyla.move (yylookahead);
  416. }
  417. catch (const syntax_error& yyexc)
  418. {
  419. error (yyexc);
  420. goto yyerrlab1;
  421. }
  422. }
  423. YY_SYMBOL_PRINT ("Next token is", yyla);
  424. /* If the proper action on seeing token YYLA.TYPE is to reduce or
  425. to detect an error, take that action. */
  426. yyn += yyla.type_get ();
  427. if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
  428. goto yydefault;
  429. // Reduce or error.
  430. yyn = yytable_[yyn];
  431. if (yyn <= 0)
  432. {
  433. if (yy_table_value_is_error_ (yyn))
  434. goto yyerrlab;
  435. yyn = -yyn;
  436. goto yyreduce;
  437. }
  438. // Count tokens shifted since error; after three, turn off error status.
  439. if (yyerrstatus_)
  440. --yyerrstatus_;
  441. // Shift the lookahead token.
  442. yypush_ ("Shifting", yyn, yyla);
  443. goto yynewstate;
  444. /*-----------------------------------------------------------.
  445. | yydefault -- do the default action for the current state. |
  446. `-----------------------------------------------------------*/
  447. yydefault:
  448. yyn = yydefact_[yystack_[0].state];
  449. if (yyn == 0)
  450. goto yyerrlab;
  451. goto yyreduce;
  452. /*-----------------------------.
  453. | yyreduce -- Do a reduction. |
  454. `-----------------------------*/
  455. yyreduce:
  456. yylen = yyr2_[yyn];
  457. {
  458. stack_symbol_type yylhs;
  459. yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);
  460. /* Variants are always initialized to an empty instance of the
  461. correct type. The default '$$ = $1' action is NOT applied
  462. when using variants. */
  463. switch (yyr1_[yyn])
  464. {
  465. case 15: // "constant string"
  466. case 16: // "integer"
  467. case 17: // "constant hexstring"
  468. case 18: // TOKEN
  469. yylhs.value.build< std::string > ();
  470. break;
  471. default:
  472. break;
  473. }
  474. // Compute the default @$.
  475. {
  476. slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
  477. YYLLOC_DEFAULT (yylhs.location, slice, yylen);
  478. }
  479. // Perform the reduction.
  480. YY_REDUCE_PRINT (yyn);
  481. try
  482. {
  483. switch (yyn)
  484. {
  485. case 3:
  486. #line 105 "parser.yy" // lalr1.cc:859
  487. {
  488. TokenPtr eq(new TokenEqual());
  489. ctx.expression.push_back(eq);
  490. }
  491. #line 601 "parser.cc" // lalr1.cc:859
  492. break;
  493. case 4:
  494. #line 112 "parser.yy" // lalr1.cc:859
  495. {
  496. TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ()));
  497. ctx.expression.push_back(str);
  498. }
  499. #line 610 "parser.cc" // lalr1.cc:859
  500. break;
  501. case 5:
  502. #line 117 "parser.yy" // lalr1.cc:859
  503. {
  504. TokenPtr hex(new TokenHexString(yystack_[0].value.as< std::string > ()));
  505. ctx.expression.push_back(hex);
  506. }
  507. #line 619 "parser.cc" // lalr1.cc:859
  508. break;
  509. case 6:
  510. #line 122 "parser.yy" // lalr1.cc:859
  511. {
  512. uint16_t numeric_code = convert_option_code(yystack_[3].value.as< std::string > (), yystack_[3].location, ctx);
  513. TokenPtr opt(new TokenOption(numeric_code, TokenOption::TEXTUAL));
  514. ctx.expression.push_back(opt);
  515. }
  516. #line 629 "parser.cc" // lalr1.cc:859
  517. break;
  518. case 7:
  519. #line 128 "parser.yy" // lalr1.cc:859
  520. {
  521. uint16_t numeric_code = convert_option_code(yystack_[3].value.as< std::string > (), yystack_[3].location, ctx);
  522. TokenPtr opt(new TokenOption(numeric_code, TokenOption::HEXADECIMAL));
  523. ctx.expression.push_back(opt);
  524. }
  525. #line 639 "parser.cc" // lalr1.cc:859
  526. break;
  527. case 8:
  528. #line 134 "parser.yy" // lalr1.cc:859
  529. {
  530. TokenPtr sub(new TokenSubstring());
  531. ctx.expression.push_back(sub);
  532. }
  533. #line 648 "parser.cc" // lalr1.cc:859
  534. break;
  535. case 10:
  536. #line 143 "parser.yy" // lalr1.cc:859
  537. {
  538. TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ()));
  539. ctx.expression.push_back(str);
  540. }
  541. #line 657 "parser.cc" // lalr1.cc:859
  542. break;
  543. case 11:
  544. #line 150 "parser.yy" // lalr1.cc:859
  545. {
  546. TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ()));
  547. ctx.expression.push_back(str);
  548. }
  549. #line 666 "parser.cc" // lalr1.cc:859
  550. break;
  551. case 12:
  552. #line 155 "parser.yy" // lalr1.cc:859
  553. {
  554. TokenPtr str(new TokenString("all"));
  555. ctx.expression.push_back(str);
  556. }
  557. #line 675 "parser.cc" // lalr1.cc:859
  558. break;
  559. #line 679 "parser.cc" // lalr1.cc:859
  560. default:
  561. break;
  562. }
  563. }
  564. catch (const syntax_error& yyexc)
  565. {
  566. error (yyexc);
  567. YYERROR;
  568. }
  569. YY_SYMBOL_PRINT ("-> $$ =", yylhs);
  570. yypop_ (yylen);
  571. yylen = 0;
  572. YY_STACK_PRINT ();
  573. // Shift the result of the reduction.
  574. yypush_ (YY_NULLPTR, yylhs);
  575. }
  576. goto yynewstate;
  577. /*--------------------------------------.
  578. | yyerrlab -- here on detecting error. |
  579. `--------------------------------------*/
  580. yyerrlab:
  581. // If not already recovering from an error, report this error.
  582. if (!yyerrstatus_)
  583. {
  584. ++yynerrs_;
  585. error (yyla.location, yysyntax_error_ (yystack_[0].state, yyla));
  586. }
  587. yyerror_range[1].location = yyla.location;
  588. if (yyerrstatus_ == 3)
  589. {
  590. /* If just tried and failed to reuse lookahead token after an
  591. error, discard it. */
  592. // Return failure if at end of input.
  593. if (yyla.type_get () == yyeof_)
  594. YYABORT;
  595. else if (!yyla.empty ())
  596. {
  597. yy_destroy_ ("Error: discarding", yyla);
  598. yyla.clear ();
  599. }
  600. }
  601. // Else will try to reuse lookahead token after shifting the error token.
  602. goto yyerrlab1;
  603. /*---------------------------------------------------.
  604. | yyerrorlab -- error raised explicitly by YYERROR. |
  605. `---------------------------------------------------*/
  606. yyerrorlab:
  607. /* Pacify compilers like GCC when the user code never invokes
  608. YYERROR and the label yyerrorlab therefore never appears in user
  609. code. */
  610. if (false)
  611. goto yyerrorlab;
  612. yyerror_range[1].location = yystack_[yylen - 1].location;
  613. /* Do not reclaim the symbols of the rule whose action triggered
  614. this YYERROR. */
  615. yypop_ (yylen);
  616. yylen = 0;
  617. goto yyerrlab1;
  618. /*-------------------------------------------------------------.
  619. | yyerrlab1 -- common code for both syntax error and YYERROR. |
  620. `-------------------------------------------------------------*/
  621. yyerrlab1:
  622. yyerrstatus_ = 3; // Each real token shifted decrements this.
  623. {
  624. stack_symbol_type error_token;
  625. for (;;)
  626. {
  627. yyn = yypact_[yystack_[0].state];
  628. if (!yy_pact_value_is_default_ (yyn))
  629. {
  630. yyn += yyterror_;
  631. if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
  632. {
  633. yyn = yytable_[yyn];
  634. if (0 < yyn)
  635. break;
  636. }
  637. }
  638. // Pop the current state because it cannot handle the error token.
  639. if (yystack_.size () == 1)
  640. YYABORT;
  641. yyerror_range[1].location = yystack_[0].location;
  642. yy_destroy_ ("Error: popping", yystack_[0]);
  643. yypop_ ();
  644. YY_STACK_PRINT ();
  645. }
  646. yyerror_range[2].location = yyla.location;
  647. YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);
  648. // Shift the error token.
  649. error_token.state = yyn;
  650. yypush_ ("Shifting", error_token);
  651. }
  652. goto yynewstate;
  653. // Accept.
  654. yyacceptlab:
  655. yyresult = 0;
  656. goto yyreturn;
  657. // Abort.
  658. yyabortlab:
  659. yyresult = 1;
  660. goto yyreturn;
  661. yyreturn:
  662. if (!yyla.empty ())
  663. yy_destroy_ ("Cleanup: discarding lookahead", yyla);
  664. /* Do not reclaim the symbols of the rule whose action triggered
  665. this YYABORT or YYACCEPT. */
  666. yypop_ (yylen);
  667. while (1 < yystack_.size ())
  668. {
  669. yy_destroy_ ("Cleanup: popping", yystack_[0]);
  670. yypop_ ();
  671. }
  672. return yyresult;
  673. }
  674. catch (...)
  675. {
  676. YYCDEBUG << "Exception caught: cleaning lookahead and stack"
  677. << std::endl;
  678. // Do not try to display the values of the reclaimed symbols,
  679. // as their printer might throw an exception.
  680. if (!yyla.empty ())
  681. yy_destroy_ (YY_NULLPTR, yyla);
  682. while (1 < yystack_.size ())
  683. {
  684. yy_destroy_ (YY_NULLPTR, yystack_[0]);
  685. yypop_ ();
  686. }
  687. throw;
  688. }
  689. }
  690. void
  691. EvalParser::error (const syntax_error& yyexc)
  692. {
  693. error (yyexc.location, yyexc.what());
  694. }
  695. // Generate an error message.
  696. std::string
  697. EvalParser::yysyntax_error_ (state_type yystate, const symbol_type& yyla) const
  698. {
  699. // Number of reported tokens (one for the "unexpected", one per
  700. // "expected").
  701. size_t yycount = 0;
  702. // Its maximum.
  703. enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  704. // Arguments of yyformat.
  705. char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  706. /* There are many possibilities here to consider:
  707. - If this state is a consistent state with a default action, then
  708. the only way this function was invoked is if the default action
  709. is an error action. In that case, don't check for expected
  710. tokens because there are none.
  711. - The only way there can be no lookahead present (in yyla) is
  712. if this state is a consistent state with a default action.
  713. Thus, detecting the absence of a lookahead is sufficient to
  714. determine that there is no unexpected or expected token to
  715. report. In that case, just report a simple "syntax error".
  716. - Don't assume there isn't a lookahead just because this state is
  717. a consistent state with a default action. There might have
  718. been a previous inconsistent state, consistent state with a
  719. non-default action, or user semantic action that manipulated
  720. yyla. (However, yyla is currently not documented for users.)
  721. - Of course, the expected token list depends on states to have
  722. correct lookahead information, and it depends on the parser not
  723. to perform extra reductions after fetching a lookahead from the
  724. scanner and before detecting a syntax error. Thus, state
  725. merging (from LALR or IELR) and default reductions corrupt the
  726. expected token list. However, the list is correct for
  727. canonical LR with one exception: it will still contain any
  728. token that will not be accepted due to an error action in a
  729. later state.
  730. */
  731. if (!yyla.empty ())
  732. {
  733. int yytoken = yyla.type_get ();
  734. yyarg[yycount++] = yytname_[yytoken];
  735. int yyn = yypact_[yystate];
  736. if (!yy_pact_value_is_default_ (yyn))
  737. {
  738. /* Start YYX at -YYN if negative to avoid negative indexes in
  739. YYCHECK. In other words, skip the first -YYN actions for
  740. this state because they are default actions. */
  741. int yyxbegin = yyn < 0 ? -yyn : 0;
  742. // Stay within bounds of both yycheck and yytname.
  743. int yychecklim = yylast_ - yyn + 1;
  744. int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
  745. for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
  746. if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_
  747. && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
  748. {
  749. if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
  750. {
  751. yycount = 1;
  752. break;
  753. }
  754. else
  755. yyarg[yycount++] = yytname_[yyx];
  756. }
  757. }
  758. }
  759. char const* yyformat = YY_NULLPTR;
  760. switch (yycount)
  761. {
  762. #define YYCASE_(N, S) \
  763. case N: \
  764. yyformat = S; \
  765. break
  766. YYCASE_(0, YY_("syntax error"));
  767. YYCASE_(1, YY_("syntax error, unexpected %s"));
  768. YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
  769. YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
  770. YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
  771. YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
  772. #undef YYCASE_
  773. }
  774. std::string yyres;
  775. // Argument number.
  776. size_t yyi = 0;
  777. for (char const* yyp = yyformat; *yyp; ++yyp)
  778. if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
  779. {
  780. yyres += yytnamerr_ (yyarg[yyi++]);
  781. ++yyp;
  782. }
  783. else
  784. yyres += *yyp;
  785. return yyres;
  786. }
  787. const signed char EvalParser::yypact_ninf_ = -10;
  788. const signed char EvalParser::yytable_ninf_ = -1;
  789. const signed char
  790. EvalParser::yypact_[] =
  791. {
  792. -4, -9, -3, -10, -10, -10, 9, -10, 12, 1,
  793. -4, -10, -4, -2, 6, -10, 10, 2, 0, -10,
  794. 11, -10, -10, -6, -10, -10, 8, -10
  795. };
  796. const unsigned char
  797. EvalParser::yydefact_[] =
  798. {
  799. 0, 0, 0, 4, 5, 9, 0, 2, 0, 0,
  800. 0, 1, 0, 0, 0, 3, 0, 0, 0, 10,
  801. 0, 6, 7, 0, 12, 11, 0, 8
  802. };
  803. const signed char
  804. EvalParser::yypgoto_[] =
  805. {
  806. -10, -10, -10, -7, -10, -10
  807. };
  808. const signed char
  809. EvalParser::yydefgoto_[] =
  810. {
  811. -1, 6, 7, 8, 20, 26
  812. };
  813. const unsigned char
  814. EvalParser::yytable_[] =
  815. {
  816. 1, 2, 24, 14, 9, 15, 21, 22, 10, 11,
  817. 25, 3, 16, 4, 5, 12, 17, 13, 19, 18,
  818. 27, 23
  819. };
  820. const unsigned char
  821. EvalParser::yycheck_[] =
  822. {
  823. 4, 5, 8, 10, 13, 12, 6, 7, 11, 0,
  824. 16, 15, 14, 17, 18, 3, 10, 16, 16, 9,
  825. 12, 10
  826. };
  827. const unsigned char
  828. EvalParser::yystos_[] =
  829. {
  830. 0, 4, 5, 15, 17, 18, 20, 21, 22, 13,
  831. 11, 0, 3, 16, 22, 22, 14, 10, 9, 16,
  832. 23, 6, 7, 10, 8, 16, 24, 12
  833. };
  834. const unsigned char
  835. EvalParser::yyr1_[] =
  836. {
  837. 0, 19, 20, 21, 22, 22, 22, 22, 22, 22,
  838. 23, 24, 24
  839. };
  840. const unsigned char
  841. EvalParser::yyr2_[] =
  842. {
  843. 0, 2, 1, 3, 1, 1, 6, 6, 8, 1,
  844. 1, 1, 1
  845. };
  846. // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
  847. // First, the terminals, then, starting at \a yyntokens_, nonterminals.
  848. const char*
  849. const EvalParser::yytname_[] =
  850. {
  851. "\"end of file\"", "error", "$undefined", "\"==\"", "\"option\"",
  852. "\"substring\"", "\"text\"", "\"hex\"", "\"all\"", "\".\"", "\",\"",
  853. "\"(\"", "\")\"", "\"[\"", "\"]\"", "\"constant string\"", "\"integer\"",
  854. "\"constant hexstring\"", "TOKEN", "$accept", "expression", "bool_expr",
  855. "string_expr", "start_expr", "length_expr", YY_NULLPTR
  856. };
  857. #if YYDEBUG
  858. const unsigned char
  859. EvalParser::yyrline_[] =
  860. {
  861. 0, 101, 101, 104, 111, 116, 121, 127, 133, 138,
  862. 142, 149, 154
  863. };
  864. // Print the state stack on the debug stream.
  865. void
  866. EvalParser::yystack_print_ ()
  867. {
  868. *yycdebug_ << "Stack now";
  869. for (stack_type::const_iterator
  870. i = yystack_.begin (),
  871. i_end = yystack_.end ();
  872. i != i_end; ++i)
  873. *yycdebug_ << ' ' << i->state;
  874. *yycdebug_ << std::endl;
  875. }
  876. // Report on the debug stream that the rule \a yyrule is going to be reduced.
  877. void
  878. EvalParser::yy_reduce_print_ (int yyrule)
  879. {
  880. unsigned int yylno = yyrline_[yyrule];
  881. int yynrhs = yyr2_[yyrule];
  882. // Print the symbols being reduced, and their result.
  883. *yycdebug_ << "Reducing stack by rule " << yyrule - 1
  884. << " (line " << yylno << "):" << std::endl;
  885. // The symbols being reduced.
  886. for (int yyi = 0; yyi < yynrhs; yyi++)
  887. YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
  888. yystack_[(yynrhs) - (yyi + 1)]);
  889. }
  890. #endif // YYDEBUG
  891. #line 21 "parser.yy" // lalr1.cc:1167
  892. } } // isc::eval
  893. #line 1058 "parser.cc" // lalr1.cc:1167
  894. #line 161 "parser.yy" // lalr1.cc:1168
  895. void
  896. isc::eval::EvalParser::error(const location_type& loc,
  897. const std::string& what)
  898. {
  899. ctx.error(loc, what);
  900. }