QJson home page
json_parser.cc
1 /* A Bison parser, made by GNU Bison 2.7. */
2 
3 /* Skeleton implementation for Bison LALR(1) parsers in C++
4 
5  Copyright (C) 2002-2012 Free Software Foundation, Inc.
6 
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 /* As a special exception, you may create a larger work that contains
21  part or all of the Bison parser skeleton and distribute that work
22  under terms of your choice, so long as that work isn't itself a
23  parser generator using the skeleton or a modified version thereof
24  as a parser skeleton. Alternatively, if you modify or redistribute
25  the parser skeleton itself, you may (at your option) remove this
26  special exception, which will cause the skeleton and the resulting
27  Bison output files to be licensed under the GNU General Public
28  License without this special exception.
29 
30  This special exception was added by the Free Software Foundation in
31  version 2.2 of Bison. */
32 
33 
34 /* First part of user declarations. */
35 
36 /* Line 279 of lalr1.cc */
37 #line 38 "json_parser.cc"
38 
39 
40 #include "json_parser.hh"
41 
42 /* User implementation prologue. */
43 
44 /* Line 285 of lalr1.cc */
45 #line 46 "json_parser.cc"
46 
47 
48 # ifndef YY_NULL
49 # if defined __cplusplus && 201103L <= __cplusplus
50 # define YY_NULL nullptr
51 # else
52 # define YY_NULL 0
53 # endif
54 # endif
55 
56 #ifndef YY_
57 # if defined YYENABLE_NLS && YYENABLE_NLS
58 # if ENABLE_NLS
59 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
60 # define YY_(msgid) dgettext ("bison-runtime", msgid)
61 # endif
62 # endif
63 # ifndef YY_
64 # define YY_(msgid) msgid
65 # endif
66 #endif
67 
68 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
69 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
70  If N is 0, then set CURRENT to the empty location which ends
71  the previous symbol: RHS[0] (always defined). */
72 
73 # ifndef YYLLOC_DEFAULT
74 # define YYLLOC_DEFAULT(Current, Rhs, N) \
75  do \
76  if (N) \
77  { \
78  (Current).begin = YYRHSLOC (Rhs, 1).begin; \
79  (Current).end = YYRHSLOC (Rhs, N).end; \
80  } \
81  else \
82  { \
83  (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
84  } \
85  while (/*CONSTCOND*/ false)
86 # endif
87 
88 
89 /* Suppress unused-variable warnings by "using" E. */
90 #define YYUSE(e) ((void) (e))
91 
92 /* Enable debugging if requested. */
93 #if YYDEBUG
94 
95 /* A pseudo ostream that takes yydebug_ into account. */
96 # define YYCDEBUG if (yydebug_) (*yycdebug_)
97 
98 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
99 do { \
100  if (yydebug_) \
101  { \
102  *yycdebug_ << Title << ' '; \
103  yy_symbol_print_ ((Type), (Value), (Location)); \
104  *yycdebug_ << std::endl; \
105  } \
106 } while (false)
107 
108 # define YY_REDUCE_PRINT(Rule) \
109 do { \
110  if (yydebug_) \
111  yy_reduce_print_ (Rule); \
112 } while (false)
113 
114 # define YY_STACK_PRINT() \
115 do { \
116  if (yydebug_) \
117  yystack_print_ (); \
118 } while (false)
119 
120 #else /* !YYDEBUG */
121 
122 # define YYCDEBUG if (false) std::cerr
123 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) YYUSE(Type)
124 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
125 # define YY_STACK_PRINT() static_cast<void>(0)
126 
127 #endif /* !YYDEBUG */
128 
129 #define yyerrok (yyerrstatus_ = 0)
130 #define yyclearin (yychar = yyempty_)
131 
132 #define YYACCEPT goto yyacceptlab
133 #define YYABORT goto yyabortlab
134 #define YYERROR goto yyerrorlab
135 #define YYRECOVERING() (!!yyerrstatus_)
136 
137 
138 namespace yy {
139 /* Line 353 of lalr1.cc */
140 #line 141 "json_parser.cc"
141 
142  /* Return YYSTR after stripping away unnecessary quotes and
143  backslashes, so that it's suitable for yyerror. The heuristic is
144  that double-quoting is unnecessary unless the string contains an
145  apostrophe, a comma, or backslash (other than backslash-backslash).
146  YYSTR is taken from yytname. */
147  std::string
148  json_parser::yytnamerr_ (const char *yystr)
149  {
150  if (*yystr == '"')
151  {
152  std::string yyr;
153  char const *yyp = yystr;
154 
155  for (;;)
156  switch (*++yyp)
157  {
158  case '\'':
159  case ',':
160  goto do_not_strip_quotes;
161 
162  case '\\':
163  if (*++yyp != '\\')
164  goto do_not_strip_quotes;
165  /* Fall through. */
166  default:
167  yyr += *yyp;
168  break;
169 
170  case '"':
171  return yyr;
172  }
173  do_not_strip_quotes: ;
174  }
175 
176  return yystr;
177  }
178 
179 
181  json_parser::json_parser (QJson::ParserPrivate* driver_yyarg)
182  :
183 #if YYDEBUG
184  yydebug_ (false),
185  yycdebug_ (&std::cerr),
186 #endif
187  driver (driver_yyarg)
188  {
189  }
190 
191  json_parser::~json_parser ()
192  {
193  }
194 
195 #if YYDEBUG
196  /*--------------------------------.
197  | Print this symbol on YYOUTPUT. |
198  `--------------------------------*/
199 
200  inline void
201  json_parser::yy_symbol_value_print_ (int yytype,
202  const semantic_type* yyvaluep, const location_type* yylocationp)
203  {
204  YYUSE (yylocationp);
205  YYUSE (yyvaluep);
206  std::ostream& yyo = debug_stream ();
207  std::ostream& yyoutput = yyo;
208  YYUSE (yyoutput);
209  switch (yytype)
210  {
211  default:
212  break;
213  }
214  }
215 
216 
217  void
218  json_parser::yy_symbol_print_ (int yytype,
219  const semantic_type* yyvaluep, const location_type* yylocationp)
220  {
221  *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
222  << ' ' << yytname_[yytype] << " ("
223  << *yylocationp << ": ";
224  yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
225  *yycdebug_ << ')';
226  }
227 #endif
228 
229  void
230  json_parser::yydestruct_ (const char* yymsg,
231  int yytype, semantic_type* yyvaluep, location_type* yylocationp)
232  {
233  YYUSE (yylocationp);
234  YYUSE (yymsg);
235  YYUSE (yyvaluep);
236 
237  if (yymsg)
238  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
239 
240  switch (yytype)
241  {
242 
243  default:
244  break;
245  }
246  }
247 
248  void
249  json_parser::yypop_ (unsigned int n)
250  {
251  yystate_stack_.pop (n);
252  yysemantic_stack_.pop (n);
253  yylocation_stack_.pop (n);
254  }
255 
256 #if YYDEBUG
257  std::ostream&
259  {
260  return *yycdebug_;
261  }
262 
263  void
265  {
266  yycdebug_ = &o;
267  }
268 
269 
272  {
273  return yydebug_;
274  }
275 
276  void
278  {
279  yydebug_ = l;
280  }
281 #endif
282 
283  inline bool
284  json_parser::yy_pact_value_is_default_ (int yyvalue)
285  {
286  return yyvalue == yypact_ninf_;
287  }
288 
289  inline bool
290  json_parser::yy_table_value_is_error_ (int yyvalue)
291  {
292  return yyvalue == yytable_ninf_;
293  }
294 
295  int
297  {
299  int yychar = yyempty_;
300  int yytoken = 0;
301 
302  // State.
303  int yyn;
304  int yylen = 0;
305  int yystate = 0;
306 
307  // Error handling.
308  int yynerrs_ = 0;
309  int yyerrstatus_ = 0;
310 
312  static semantic_type yyval_default;
313  semantic_type yylval = yyval_default;
315  location_type yylloc;
317  location_type yyerror_range[3];
318 
320  semantic_type yyval;
322  location_type yyloc;
323 
324  int yyresult;
325 
326  // FIXME: This shoud be completely indented. It is not yet to
327  // avoid gratuitous conflicts when merging into the master branch.
328  try
329  {
330  YYCDEBUG << "Starting parse" << std::endl;
331 
332 
333  /* Initialize the stacks. The initial state will be pushed in
334  yynewstate, since the latter expects the semantical and the
335  location values to have been already stored, initialize these
336  stacks with a primary value. */
337  yystate_stack_ = state_stack_type (0);
338  yysemantic_stack_ = semantic_stack_type (0);
339  yylocation_stack_ = location_stack_type (0);
340  yysemantic_stack_.push (yylval);
341  yylocation_stack_.push (yylloc);
342 
343  /* New state. */
344  yynewstate:
345  yystate_stack_.push (yystate);
346  YYCDEBUG << "Entering state " << yystate << std::endl;
347 
348  /* Accept? */
349  if (yystate == yyfinal_)
350  goto yyacceptlab;
351 
352  goto yybackup;
353 
354  /* Backup. */
355  yybackup:
356 
357  /* Try to take a decision without lookahead. */
358  yyn = yypact_[yystate];
359  if (yy_pact_value_is_default_ (yyn))
360  goto yydefault;
361 
362  /* Read a lookahead token. */
363  if (yychar == yyempty_)
364  {
365  YYCDEBUG << "Reading a token: ";
366  yychar = yylex (&yylval, &yylloc, driver);
367  }
368 
369  /* Convert token to internal form. */
370  if (yychar <= yyeof_)
371  {
372  yychar = yytoken = yyeof_;
373  YYCDEBUG << "Now at end of input." << std::endl;
374  }
375  else
376  {
377  yytoken = yytranslate_ (yychar);
378  YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
379  }
380 
381  /* If the proper action on seeing token YYTOKEN is to reduce or to
382  detect an error, take that action. */
383  yyn += yytoken;
384  if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
385  goto yydefault;
386 
387  /* Reduce or error. */
388  yyn = yytable_[yyn];
389  if (yyn <= 0)
390  {
391  if (yy_table_value_is_error_ (yyn))
392  goto yyerrlab;
393  yyn = -yyn;
394  goto yyreduce;
395  }
396 
397  /* Shift the lookahead token. */
398  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
399 
400  /* Discard the token being shifted. */
401  yychar = yyempty_;
402 
403  yysemantic_stack_.push (yylval);
404  yylocation_stack_.push (yylloc);
405 
406  /* Count tokens shifted since error; after three, turn off error
407  status. */
408  if (yyerrstatus_)
409  --yyerrstatus_;
410 
411  yystate = yyn;
412  goto yynewstate;
413 
414  /*-----------------------------------------------------------.
415  | yydefault -- do the default action for the current state. |
416  `-----------------------------------------------------------*/
417  yydefault:
418  yyn = yydefact_[yystate];
419  if (yyn == 0)
420  goto yyerrlab;
421  goto yyreduce;
422 
423  /*-----------------------------.
424  | yyreduce -- Do a reduction. |
425  `-----------------------------*/
426  yyreduce:
427  yylen = yyr2_[yyn];
428  /* If YYLEN is nonzero, implement the default value of the action:
429  `$$ = $1'. Otherwise, use the top of the stack.
430 
431  Otherwise, the following line sets YYVAL to garbage.
432  This behavior is undocumented and Bison
433  users should not rely upon it. */
434  if (yylen)
435  yyval = yysemantic_stack_[yylen - 1];
436  else
437  yyval = yysemantic_stack_[0];
438 
439  // Compute the default @$.
440  {
441  slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
442  YYLLOC_DEFAULT (yyloc, slice, yylen);
443  }
444 
445  // Perform the reduction.
446  YY_REDUCE_PRINT (yyn);
447  switch (yyn)
448  {
449  case 2:
450 /* Line 670 of lalr1.cc */
451 #line 82 "json_parser.yy"
452  {
453  driver->m_result = (yysemantic_stack_[(1) - (1)]);
454  qjsonDebug() << "json_parser - parsing finished";
455  }
456  break;
457 
458  case 3:
459 /* Line 670 of lalr1.cc */
460 #line 87 "json_parser.yy"
461  { (yyval) = (yysemantic_stack_[(1) - (1)]); }
462  break;
463 
464  case 4:
465 /* Line 670 of lalr1.cc */
466 #line 89 "json_parser.yy"
467  {
468  qCritical()<< "json_parser - syntax error found, "
469  << "forcing abort, Line" << (yyloc).begin.line << "Column" << (yyloc).begin.column;
470  YYABORT;
471  }
472  break;
473 
474  case 5:
475 /* Line 670 of lalr1.cc */
476 #line 95 "json_parser.yy"
477  {
478  (yyval) = QVariant(QVariantMap());
479  }
480  break;
481 
482  case 6:
483 /* Line 670 of lalr1.cc */
484 #line 98 "json_parser.yy"
485  {
486  QVariantMap* map = (yysemantic_stack_[(3) - (2)]).value<QVariantMap*>();
487  (yyval) = QVariant(*map);
488  delete map;
489  }
490  break;
491 
492  case 7:
493 /* Line 670 of lalr1.cc */
494 #line 104 "json_parser.yy"
495  {
496  QVariantMap* pair = new QVariantMap();
497  pair->insert((yysemantic_stack_[(3) - (1)]).toString(), (yysemantic_stack_[(3) - (3)]));
498  (yyval).setValue<QVariantMap* >(pair);
499  }
500  break;
501 
502  case 8:
503 /* Line 670 of lalr1.cc */
504 #line 109 "json_parser.yy"
505  {
506  (yyval).value<QVariantMap*>()->insert((yysemantic_stack_[(5) - (3)]).toString(), (yysemantic_stack_[(5) - (5)]));
507  }
508  break;
509 
510  case 9:
511 /* Line 670 of lalr1.cc */
512 #line 113 "json_parser.yy"
513  {
514  (yyval) = QVariant(QVariantList());
515  }
516  break;
517 
518  case 10:
519 /* Line 670 of lalr1.cc */
520 #line 116 "json_parser.yy"
521  {
522  QVector<QVariant>* list = (yysemantic_stack_[(3) - (2)]).value<QVector<QVariant>* >();
523  (yyval) = QVariant(list->toList());
524  delete list;
525  }
526  break;
527 
528  case 11:
529 /* Line 670 of lalr1.cc */
530 #line 122 "json_parser.yy"
531  {
532  QVector<QVariant>* list = new QVector<QVariant>(1);
533  list->replace(0, (yysemantic_stack_[(1) - (1)]));
534  (yyval).setValue(list);
535  }
536  break;
537 
538  case 12:
539 /* Line 670 of lalr1.cc */
540 #line 127 "json_parser.yy"
541  {
542  (yyval).value<QVector<QVariant>* >()->append((yysemantic_stack_[(3) - (3)]));
543  }
544  break;
545 
546 
547 /* Line 670 of lalr1.cc */
548 #line 549 "json_parser.cc"
549  default:
550  break;
551  }
552 
553  /* User semantic actions sometimes alter yychar, and that requires
554  that yytoken be updated with the new translation. We take the
555  approach of translating immediately before every use of yytoken.
556  One alternative is translating here after every semantic action,
557  but that translation would be missed if the semantic action
558  invokes YYABORT, YYACCEPT, or YYERROR immediately after altering
559  yychar. In the case of YYABORT or YYACCEPT, an incorrect
560  destructor might then be invoked immediately. In the case of
561  YYERROR, subsequent parser actions might lead to an incorrect
562  destructor call or verbose syntax error message before the
563  lookahead is translated. */
564  YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
565 
566  yypop_ (yylen);
567  yylen = 0;
568  YY_STACK_PRINT ();
569 
570  yysemantic_stack_.push (yyval);
571  yylocation_stack_.push (yyloc);
572 
573  /* Shift the result of the reduction. */
574  yyn = yyr1_[yyn];
575  yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
576  if (0 <= yystate && yystate <= yylast_
577  && yycheck_[yystate] == yystate_stack_[0])
578  yystate = yytable_[yystate];
579  else
580  yystate = yydefgoto_[yyn - yyntokens_];
581  goto yynewstate;
582 
583  /*------------------------------------.
584  | yyerrlab -- here on detecting error |
585  `------------------------------------*/
586  yyerrlab:
587  /* Make sure we have latest lookahead translation. See comments at
588  user semantic actions for why this is necessary. */
589  yytoken = yytranslate_ (yychar);
590 
591  /* If not already recovering from an error, report this error. */
592  if (!yyerrstatus_)
593  {
594  ++yynerrs_;
595  if (yychar == yyempty_)
596  yytoken = yyempty_;
597  error (yylloc, yysyntax_error_ (yystate, yytoken));
598  }
599 
600  yyerror_range[1] = yylloc;
601  if (yyerrstatus_ == 3)
602  {
603  /* If just tried and failed to reuse lookahead token after an
604  error, discard it. */
605  if (yychar <= yyeof_)
606  {
607  /* Return failure if at end of input. */
608  if (yychar == yyeof_)
609  YYABORT;
610  }
611  else
612  {
613  yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
614  yychar = yyempty_;
615  }
616  }
617 
618  /* Else will try to reuse lookahead token after shifting the error
619  token. */
620  goto yyerrlab1;
621 
622 
623  /*---------------------------------------------------.
624  | yyerrorlab -- error raised explicitly by YYERROR. |
625  `---------------------------------------------------*/
626  yyerrorlab:
627 
628  /* Pacify compilers like GCC when the user code never invokes
629  YYERROR and the label yyerrorlab therefore never appears in user
630  code. */
631  if (false)
632  goto yyerrorlab;
633 
634  yyerror_range[1] = yylocation_stack_[yylen - 1];
635  /* Do not reclaim the symbols of the rule which action triggered
636  this YYERROR. */
637  yypop_ (yylen);
638  yylen = 0;
639  yystate = yystate_stack_[0];
640  goto yyerrlab1;
641 
642  /*-------------------------------------------------------------.
643  | yyerrlab1 -- common code for both syntax error and YYERROR. |
644  `-------------------------------------------------------------*/
645  yyerrlab1:
646  yyerrstatus_ = 3; /* Each real token shifted decrements this. */
647 
648  for (;;)
649  {
650  yyn = yypact_[yystate];
651  if (!yy_pact_value_is_default_ (yyn))
652  {
653  yyn += yyterror_;
654  if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
655  {
656  yyn = yytable_[yyn];
657  if (0 < yyn)
658  break;
659  }
660  }
661 
662  /* Pop the current state because it cannot handle the error token. */
663  if (yystate_stack_.height () == 1)
664  YYABORT;
665 
666  yyerror_range[1] = yylocation_stack_[0];
667  yydestruct_ ("Error: popping",
668  yystos_[yystate],
669  &yysemantic_stack_[0], &yylocation_stack_[0]);
670  yypop_ ();
671  yystate = yystate_stack_[0];
672  YY_STACK_PRINT ();
673  }
674 
675  yyerror_range[2] = yylloc;
676  // Using YYLLOC is tempting, but would change the location of
677  // the lookahead. YYLOC is available though.
678  YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
679  yysemantic_stack_.push (yylval);
680  yylocation_stack_.push (yyloc);
681 
682  /* Shift the error token. */
683  YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
684  &yysemantic_stack_[0], &yylocation_stack_[0]);
685 
686  yystate = yyn;
687  goto yynewstate;
688 
689  /* Accept. */
690  yyacceptlab:
691  yyresult = 0;
692  goto yyreturn;
693 
694  /* Abort. */
695  yyabortlab:
696  yyresult = 1;
697  goto yyreturn;
698 
699  yyreturn:
700  if (yychar != yyempty_)
701  {
702  /* Make sure we have latest lookahead translation. See comments
703  at user semantic actions for why this is necessary. */
704  yytoken = yytranslate_ (yychar);
705  yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval,
706  &yylloc);
707  }
708 
709  /* Do not reclaim the symbols of the rule which action triggered
710  this YYABORT or YYACCEPT. */
711  yypop_ (yylen);
712  while (1 < yystate_stack_.height ())
713  {
714  yydestruct_ ("Cleanup: popping",
715  yystos_[yystate_stack_[0]],
716  &yysemantic_stack_[0],
717  &yylocation_stack_[0]);
718  yypop_ ();
719  }
720 
721  return yyresult;
722  }
723  catch (...)
724  {
725  YYCDEBUG << "Exception caught: cleaning lookahead and stack"
726  << std::endl;
727  // Do not try to display the values of the reclaimed symbols,
728  // as their printer might throw an exception.
729  if (yychar != yyempty_)
730  {
731  /* Make sure we have latest lookahead translation. See
732  comments at user semantic actions for why this is
733  necessary. */
734  yytoken = yytranslate_ (yychar);
735  yydestruct_ (YY_NULL, yytoken, &yylval, &yylloc);
736  }
737 
738  while (1 < yystate_stack_.height ())
739  {
740  yydestruct_ (YY_NULL,
741  yystos_[yystate_stack_[0]],
742  &yysemantic_stack_[0],
743  &yylocation_stack_[0]);
744  yypop_ ();
745  }
746  throw;
747  }
748  }
749 
750  // Generate an error message.
751  std::string
752  json_parser::yysyntax_error_ (int yystate, int yytoken)
753  {
754  std::string yyres;
755  // Number of reported tokens (one for the "unexpected", one per
756  // "expected").
757  size_t yycount = 0;
758  // Its maximum.
759  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
760  // Arguments of yyformat.
761  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
762 
763  /* There are many possibilities here to consider:
764  - If this state is a consistent state with a default action, then
765  the only way this function was invoked is if the default action
766  is an error action. In that case, don't check for expected
767  tokens because there are none.
768  - The only way there can be no lookahead present (in yytoken) is
769  if this state is a consistent state with a default action.
770  Thus, detecting the absence of a lookahead is sufficient to
771  determine that there is no unexpected or expected token to
772  report. In that case, just report a simple "syntax error".
773  - Don't assume there isn't a lookahead just because this state is
774  a consistent state with a default action. There might have
775  been a previous inconsistent state, consistent state with a
776  non-default action, or user semantic action that manipulated
777  yychar.
778  - Of course, the expected token list depends on states to have
779  correct lookahead information, and it depends on the parser not
780  to perform extra reductions after fetching a lookahead from the
781  scanner and before detecting a syntax error. Thus, state
782  merging (from LALR or IELR) and default reductions corrupt the
783  expected token list. However, the list is correct for
784  canonical LR with one exception: it will still contain any
785  token that will not be accepted due to an error action in a
786  later state.
787  */
788  if (yytoken != yyempty_)
789  {
790  yyarg[yycount++] = yytname_[yytoken];
791  int yyn = yypact_[yystate];
792  if (!yy_pact_value_is_default_ (yyn))
793  {
794  /* Start YYX at -YYN if negative to avoid negative indexes in
795  YYCHECK. In other words, skip the first -YYN actions for
796  this state because they are default actions. */
797  int yyxbegin = yyn < 0 ? -yyn : 0;
798  /* Stay within bounds of both yycheck and yytname. */
799  int yychecklim = yylast_ - yyn + 1;
800  int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
801  for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
802  if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_
803  && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
804  {
805  if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
806  {
807  yycount = 1;
808  break;
809  }
810  else
811  yyarg[yycount++] = yytname_[yyx];
812  }
813  }
814  }
815 
816  char const* yyformat = YY_NULL;
817  switch (yycount)
818  {
819 #define YYCASE_(N, S) \
820  case N: \
821  yyformat = S; \
822  break
823  YYCASE_(0, YY_("syntax error"));
824  YYCASE_(1, YY_("syntax error, unexpected %s"));
825  YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
826  YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
827  YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
828  YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
829 #undef YYCASE_
830  }
831 
832  // Argument number.
833  size_t yyi = 0;
834  for (char const* yyp = yyformat; *yyp; ++yyp)
835  if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
836  {
837  yyres += yytnamerr_ (yyarg[yyi++]);
838  ++yyp;
839  }
840  else
841  yyres += *yyp;
842  return yyres;
843  }
844 
845 
846  /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
847  STATE-NUM. */
848  const signed char json_parser::yypact_ninf_ = -5;
849  const signed char
850  json_parser::yypact_[] =
851  {
852  0, -5, 2, 18, -5, -5, -5, -5, -5, 7,
853  -5, -5, -5, -5, -5, 1, 12, -5, -4, -5,
854  -5, 29, -5, 4, -5, 29, -5, 26, -5, 29,
855  -5
856  };
857 
858  /* YYDEFACT[S] -- default reduction number in state S. Performed when
859  YYTABLE doesn't specify something else to do. Zero means the
860  default is an error. */
861  const unsigned char
862  json_parser::yydefact_[] =
863  {
864  0, 4, 0, 0, 14, 15, 16, 17, 13, 0,
865  2, 18, 19, 3, 5, 0, 0, 9, 0, 11,
866  1, 0, 6, 0, 10, 0, 7, 0, 12, 0,
867  8
868  };
869 
870  /* YYPGOTO[NTERM-NUM]. */
871  const signed char
872  json_parser::yypgoto_[] =
873  {
874  -5, -5, -5, -5, -5, -5, -5, -3
875  };
876 
877  /* YYDEFGOTO[NTERM-NUM]. */
878  const signed char
879  json_parser::yydefgoto_[] =
880  {
881  -1, 9, 10, 11, 16, 12, 18, 13
882  };
883 
884  /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
885  positive, shift that token. If negative, reduce the rule which
886  number is the opposite. If YYTABLE_NINF_, syntax error. */
887  const signed char json_parser::yytable_ninf_ = -1;
888  const unsigned char
889  json_parser::yytable_[] =
890  {
891  19, 1, 24, 2, 25, 3, 14, 20, 21, 4,
892  5, 6, 7, 8, 0, 15, 22, 27, 26, 0,
893  23, 2, 28, 3, 17, 0, 30, 4, 5, 6,
894  7, 8, 2, 29, 3, 0, 0, 0, 4, 5,
895  6, 7, 8
896  };
897 
898  /* YYCHECK. */
899  const signed char
900  json_parser::yycheck_[] =
901  {
902  3, 1, 6, 3, 8, 5, 4, 0, 7, 9,
903  10, 11, 12, 13, -1, 13, 4, 13, 21, -1,
904  8, 3, 25, 5, 6, -1, 29, 9, 10, 11,
905  12, 13, 3, 7, 5, -1, -1, -1, 9, 10,
906  11, 12, 13
907  };
908 
909  /* STOS_[STATE-NUM] -- The (internal number of the) accessing
910  symbol of state STATE-NUM. */
911  const unsigned char
912  json_parser::yystos_[] =
913  {
914  0, 1, 3, 5, 9, 10, 11, 12, 13, 16,
915  17, 18, 20, 22, 4, 13, 19, 6, 21, 22,
916  0, 7, 4, 8, 6, 8, 22, 13, 22, 7,
917  22
918  };
919 
920 #if YYDEBUG
921  /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
922  to YYLEX-NUM. */
923  const unsigned short int
924  json_parser::yytoken_number_[] =
925  {
926  0, 256, 257, 1, 2, 3, 4, 5, 6, 7,
927  8, 9, 10, 11, 12
928  };
929 #endif
930 
931  /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
932  const unsigned char
933  json_parser::yyr1_[] =
934  {
935  0, 15, 16, 17, 17, 18, 18, 19, 19, 20,
936  20, 21, 21, 22, 22, 22, 22, 22, 22, 22
937  };
938 
939  /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
940  const unsigned char
941  json_parser::yyr2_[] =
942  {
943  0, 2, 1, 1, 1, 2, 3, 3, 5, 2,
944  3, 1, 3, 1, 1, 1, 1, 1, 1, 1
945  };
946 
947 
948  /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
949  First, the terminals, then, starting at \a yyntokens_, nonterminals. */
950  const char*
951  const json_parser::yytname_[] =
952  {
953  "\"end of file\"", "error", "$undefined", "\"{\"", "\"}\"", "\"[\"",
954  "\"]\"", "\":\"", "\",\"", "\"number\"", "\"true\"", "\"false\"",
955  "\"null\"", "\"string\"", "\"invalid\"", "$accept", "start", "data",
956  "object", "members", "array", "values", "value", YY_NULL
957  };
958 
959 #if YYDEBUG
960  /* YYRHS -- A `-1'-separated list of the rules' RHS. */
961  const json_parser::rhs_number_type
962  json_parser::yyrhs_[] =
963  {
964  16, 0, -1, 17, -1, 22, -1, 1, -1, 3,
965  4, -1, 3, 19, 4, -1, 13, 7, 22, -1,
966  19, 8, 13, 7, 22, -1, 5, 6, -1, 5,
967  21, 6, -1, 22, -1, 21, 8, 22, -1, 13,
968  -1, 9, -1, 10, -1, 11, -1, 12, -1, 18,
969  -1, 20, -1
970  };
971 
972  /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
973  YYRHS. */
974  const unsigned char
975  json_parser::yyprhs_[] =
976  {
977  0, 0, 3, 5, 7, 9, 12, 16, 20, 26,
978  29, 33, 35, 39, 41, 43, 45, 47, 49, 51
979  };
980 
981  /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
982  const unsigned char
983  json_parser::yyrline_[] =
984  {
985  0, 82, 82, 87, 88, 95, 98, 104, 109, 113,
986  116, 122, 127, 131, 132, 133, 134, 135, 136, 137
987  };
988 
989  // Print the state stack on the debug stream.
990  void
991  json_parser::yystack_print_ ()
992  {
993  *yycdebug_ << "Stack now";
994  for (state_stack_type::const_iterator i = yystate_stack_.begin ();
995  i != yystate_stack_.end (); ++i)
996  *yycdebug_ << ' ' << *i;
997  *yycdebug_ << std::endl;
998  }
999 
1000  // Report on the debug stream that the rule \a yyrule is going to be reduced.
1001  void
1002  json_parser::yy_reduce_print_ (int yyrule)
1003  {
1004  unsigned int yylno = yyrline_[yyrule];
1005  int yynrhs = yyr2_[yyrule];
1006  /* Print the symbols being reduced, and their result. */
1007  *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1008  << " (line " << yylno << "):" << std::endl;
1009  /* The symbols being reduced. */
1010  for (int yyi = 0; yyi < yynrhs; yyi++)
1011  YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1012  yyrhs_[yyprhs_[yyrule] + yyi],
1013  &(yysemantic_stack_[(yynrhs) - (yyi + 1)]),
1014  &(yylocation_stack_[(yynrhs) - (yyi + 1)]));
1015  }
1016 #endif // YYDEBUG
1017 
1018  /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1019  json_parser::token_number_type
1020  json_parser::yytranslate_ (int t)
1021  {
1022  static
1023  const token_number_type
1024  translate_table[] =
1025  {
1026  0, 3, 4, 5, 6, 7, 8, 9, 10, 11,
1027  12, 13, 14, 2, 2, 2, 2, 2, 2, 2,
1028  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1029  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1030  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1031  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1032  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1033  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1034  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1035  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1036  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1037  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1038  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1039  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1040  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1041  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1042  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1043  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1044  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1045  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1046  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1047  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1048  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1049  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1050  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1051  2, 2, 2, 2, 2, 2, 1, 2
1052  };
1053  if ((unsigned int) t <= yyuser_token_number_max_)
1054  return translate_table[t];
1055  else
1056  return yyundef_token_;
1057  }
1058 
1059  const int json_parser::yyeof_ = 0;
1060  const int json_parser::yylast_ = 42;
1061  const int json_parser::yynnts_ = 8;
1062  const int json_parser::yyempty_ = -2;
1063  const int json_parser::yyfinal_ = 20;
1064  const int json_parser::yyterror_ = 1;
1065  const int json_parser::yyerrcode_ = 256;
1066  const int json_parser::yyntokens_ = 15;
1067 
1068  const unsigned int json_parser::yyuser_token_number_max_ = 257;
1069  const json_parser::token_number_type json_parser::yyundef_token_ = 2;
1070 
1071 
1072 } // yy
1073 /* Line 1141 of lalr1.cc */
1074 #line 1075 "json_parser.cc"
1075 /* Line 1142 of lalr1.cc */
1076 #line 139 "json_parser.yy"
1077 
1078 
1079 int yy::yylex(YYSTYPE *yylval, yy::location *yylloc, QJson::ParserPrivate* driver)
1080 {
1081  JSonScanner* scanner = driver->m_scanner;
1082  yylval->clear();
1083  int ret = scanner->yylex(yylval, yylloc);
1084 
1085  qjsonDebug() << "json_parser::yylex - calling scanner yylval==|"
1086  << yylval->toByteArray() << "|, ret==|" << QString::number(ret) << "|";
1087 
1088  return ret;
1089 }
1090 
1091 void yy::json_parser::error (const yy::location& yyloc, const std::string& error)
1092 {
1093  /*qjsonDebug() << yyloc.begin.line;
1094  qjsonDebug() << yyloc.begin.column;
1095  qjsonDebug() << yyloc.end.line;
1096  qjsonDebug() << yyloc.end.column;*/
1097  qjsonDebug() << "json_parser::error [line" << yyloc.end.line << "] -" << error.c_str() ;
1098  driver->setError(QString::fromLatin1(error.c_str()), yyloc.end.line);
1099 }
json_parser(QJson::ParserPrivate *driver_yyarg)
Build a parser object.
Definition: json_parser.cc:181
debug_level_type debug_level() const
The current debugging level.
Definition: json_parser.cc:271
virtual int parse()
Definition: json_parser.cc:296
int debug_level_type
Type for debugging levels.
Definition: json_parser.hh:140
void set_debug_level(debug_level_type l)
Set the current debugging level.
Definition: json_parser.cc:277
std::ostream & debug_stream() const
The current debugging stream.
Definition: json_parser.cc:258
YYSTYPE semantic_type
Symbol semantic values.
Definition: json_parser.hh:97
void set_debug_stream(std::ostream &)
Set the current debugging stream.
Definition: json_parser.cc:264
Abstract a location.
Definition: location.hh:50
position end
End of the located region.
Definition: location.hh:113
unsigned int line
Current line number.
Definition: position.hh:102
Present a slice of the top of a stack.
Definition: stack.hh:109

SourceForge Logo hosts this site. Send comments to:
QJson Developers