parser.cc 31 KB

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