parser.cc 32 KB

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