parser.cc 26 KB

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