parser.cc 30 KB

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