parser.cc 30 KB

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