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

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