1 /* A Bison parser, made by GNU Bison 2.1. */
3 /* Skeleton parser for Yacc-like parsing with Bison,
4 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
21 /* As a special exception, when this file is copied by Bison into a
22 Bison output file, you may use that output file without restriction.
23 This special exception was added by the Free Software Foundation
24 in version 1.24 of Bison. */
26 /* Written by Richard Stallman by simplifying the original so called
27 ``semantic'' parser. */
29 /* All symbols defined below should begin with yy or YY, to avoid
30 infringing on user name space. This should be done even for local
31 variables, as they might otherwise be expanded by user macros.
32 There are some unavoidable exceptions within include files to
33 define necessary library symbols; they are noted "INFRINGES ON
34 USER NAME SPACE" below. */
36 /* Identify Bison output. */
40 #define YYBISON_VERSION "2.1"
43 #define YYSKELETON_NAME "yacc.c"
48 /* Using locations. */
49 #define YYLSP_NEEDED 0
51 /* Substitute the variable and function names. */
52 #define yyparse cql_parse
54 #define yyerror cql_error
55 #define yylval cql_lval
56 #define yychar cql_char
57 #define yydebug cql_debug
58 #define yynerrs cql_nerrs
64 /* Put the tokens into the symbol table, so that GDB and other debuggers
90 /* Copy the first part of user declarations. */
95 * \brief Implements CQL parser.
97 * This is a YACC parser, but since it must be reentrant, Bison is required.
98 * The original source file is cql.y.
104 #include <yaz/xmalloc.h>
105 #include <yaz/nmem.h>
108 /** Node in the LALR parse tree. */
110 /** Inhereted attribute: relation */
111 struct cql_node *rel;
112 /** Synthesized attribute: CQL node */
113 struct cql_node *cql;
114 /** string buffer with token */
116 /** length of token */
118 /** size of buffer (len <= size) */
123 int (*getbyte)(void *client_data);
124 void (*ungetbyte)(int b, void *client_data);
128 struct cql_node *top;
132 #define YYSTYPE token
134 #define YYPARSE_PARAM parm
135 #define YYLEX_PARAM parm
137 int yylex(YYSTYPE *lval, void *vp);
138 int yyerror(char *s);
141 /* Enabling traces. */
146 /* Enabling verbose error messages. */
147 #ifdef YYERROR_VERBOSE
148 # undef YYERROR_VERBOSE
149 # define YYERROR_VERBOSE 1
151 # define YYERROR_VERBOSE 0
154 /* Enabling the token table. */
155 #ifndef YYTOKEN_TABLE
156 # define YYTOKEN_TABLE 0
159 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
161 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
162 # define YYSTYPE_IS_DECLARED 1
163 # define YYSTYPE_IS_TRIVIAL 1
168 /* Copy the second part of user declarations. */
171 /* Line 219 of yacc.c. */
174 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
175 # define YYSIZE_T __SIZE_TYPE__
177 #if ! defined (YYSIZE_T) && defined (size_t)
178 # define YYSIZE_T size_t
180 #if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
181 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
182 # define YYSIZE_T size_t
184 #if ! defined (YYSIZE_T)
185 # define YYSIZE_T unsigned int
191 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
192 # define YY_(msgid) dgettext ("bison-runtime", msgid)
196 # define YY_(msgid) msgid
200 #if ! defined (yyoverflow) || YYERROR_VERBOSE
202 /* The parser invokes alloca or malloc; define the necessary symbols. */
204 # ifdef YYSTACK_USE_ALLOCA
205 # if YYSTACK_USE_ALLOCA
207 # define YYSTACK_ALLOC __builtin_alloca
209 # define YYSTACK_ALLOC alloca
210 # if defined (__STDC__) || defined (__cplusplus)
211 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
212 # define YYINCLUDED_STDLIB_H
218 # ifdef YYSTACK_ALLOC
219 /* Pacify GCC's `empty if-body' warning. */
220 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
221 # ifndef YYSTACK_ALLOC_MAXIMUM
222 /* The OS might guarantee only one guard page at the bottom of the stack,
223 and a page size can be as small as 4096 bytes. So we cannot safely
224 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
225 to allow for a few compiler-allocated temporary stack slots. */
226 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */
229 # define YYSTACK_ALLOC YYMALLOC
230 # define YYSTACK_FREE YYFREE
231 # ifndef YYSTACK_ALLOC_MAXIMUM
232 # define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1)
238 # define YYMALLOC malloc
239 # if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \
240 && (defined (__STDC__) || defined (__cplusplus)))
241 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
246 # if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \
247 && (defined (__STDC__) || defined (__cplusplus)))
248 void free (void *); /* INFRINGES ON USER NAME SPACE */
255 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
258 #if (! defined (yyoverflow) \
259 && (! defined (__cplusplus) \
260 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
262 /* A type that is properly aligned for any stack member. */
269 /* The size of the maximum gap between one aligned stack and the next. */
270 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
272 /* The size of an array large to enough to hold all stacks, each with
274 # define YYSTACK_BYTES(N) \
275 ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \
276 + YYSTACK_GAP_MAXIMUM)
278 /* Copy COUNT objects from FROM to TO. The source and destination do
281 # if defined (__GNUC__) && 1 < __GNUC__
282 # define YYCOPY(To, From, Count) \
283 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
285 # define YYCOPY(To, From, Count) \
289 for (yyi = 0; yyi < (Count); yyi++) \
290 (To)[yyi] = (From)[yyi]; \
296 /* Relocate STACK from its old location to the new one. The
297 local variables YYSIZE and YYSTACKSIZE give the old and new number of
298 elements in the stack, and YYPTR gives the new location of the
299 stack. Advance YYPTR to a properly aligned location for the next
301 # define YYSTACK_RELOCATE(Stack) \
304 YYSIZE_T yynewbytes; \
305 YYCOPY (&yyptr->Stack, Stack, yysize); \
306 Stack = &yyptr->Stack; \
307 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
308 yyptr += yynewbytes / sizeof (*yyptr); \
314 #if defined (__STDC__) || defined (__cplusplus)
315 typedef signed char yysigned_char;
317 typedef short int yysigned_char;
320 /* YYFINAL -- State number of the termination state. */
322 /* YYLAST -- Last index in YYTABLE. */
325 /* YYNTOKENS -- Number of terminals. */
327 /* YYNNTS -- Number of nonterminals. */
329 /* YYNRULES -- Number of rules. */
331 /* YYNRULES -- Number of states. */
334 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
336 #define YYMAXUTOK 265
338 #define YYTRANSLATE(YYX) \
339 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
341 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
342 static const unsigned char yytranslate[] =
344 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
345 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
346 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
347 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
348 11, 12, 2, 2, 2, 2, 2, 15, 2, 2,
349 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
350 16, 14, 13, 2, 2, 2, 2, 2, 2, 2,
351 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
352 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
353 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
354 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
355 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
356 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
357 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
358 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
359 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
360 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
361 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
362 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
363 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
364 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
365 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
366 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
367 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
368 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
369 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
374 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
376 static const unsigned char yyprhs[] =
378 0, 0, 3, 4, 7, 9, 12, 14, 15, 21,
379 22, 27, 29, 30, 36, 37, 44, 45, 50, 52,
380 54, 56, 58, 62, 68, 69, 71, 73, 75, 77,
381 79, 81, 83, 85, 87, 89, 91, 93, 95, 97,
385 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
386 static const yysigned_char yyrhs[] =
388 18, 0, -1, -1, 19, 20, -1, 21, -1, 21,
389 1, -1, 23, -1, -1, 21, 28, 29, 22, 23,
390 -1, -1, 11, 24, 21, 12, -1, 33, -1, -1,
391 32, 31, 29, 25, 23, -1, -1, 13, 33, 14,
392 33, 26, 21, -1, -1, 13, 33, 27, 21, -1,
393 4, -1, 5, -1, 6, -1, 7, -1, 29, 15,
394 33, -1, 29, 15, 33, 30, 33, -1, -1, 14,
395 -1, 13, -1, 16, -1, 8, -1, 9, -1, 10,
396 -1, 14, -1, 13, -1, 16, -1, 8, -1, 9,
397 -1, 10, -1, 3, -1, 33, -1, 3, -1, 4,
398 -1, 5, -1, 6, -1, 7, -1
401 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
402 static const unsigned char yyrline[] =
404 0, 66, 66, 66, 76, 77, 84, 86, 86, 101,
405 101, 108, 114, 114, 121, 121, 127, 127, 138, 138,
406 138, 138, 141, 150, 159, 165, 166, 167, 168, 169,
407 170, 174, 175, 176, 177, 178, 179, 180, 184, 187,
412 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
413 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
414 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
415 static const char *const yytname[] =
417 "$end", "error", "$undefined", "TERM", "AND", "OR", "NOT", "PROX", "GE",
418 "LE", "NE", "'('", "')'", "'>'", "'='", "'/'", "'<'", "$accept", "top",
419 "@1", "cqlQuery1", "cqlQuery", "@2", "searchClause", "@3", "@4", "@5",
420 "@6", "boolean", "modifiers", "mrelation", "relation", "index",
426 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
428 static const unsigned short int yytoknum[] =
430 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
431 265, 40, 41, 62, 61, 47, 60
435 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
436 static const unsigned char yyr1[] =
438 0, 17, 19, 18, 20, 20, 21, 22, 21, 24,
439 23, 23, 25, 23, 26, 23, 27, 23, 28, 28,
440 28, 28, 29, 29, 29, 30, 30, 30, 30, 30,
441 30, 31, 31, 31, 31, 31, 31, 31, 32, 33,
445 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
446 static const unsigned char yyr2[] =
448 0, 2, 0, 2, 1, 2, 1, 0, 5, 0,
449 4, 1, 0, 5, 0, 6, 0, 4, 1, 1,
450 1, 1, 3, 5, 0, 1, 1, 1, 1, 1,
451 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
455 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
456 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
457 means the default is an error. */
458 static const unsigned char yydefact[] =
460 2, 0, 0, 1, 39, 40, 41, 42, 43, 9,
461 0, 3, 0, 6, 0, 11, 0, 16, 5, 18,
462 19, 20, 21, 24, 37, 34, 35, 36, 32, 31,
463 33, 24, 0, 0, 0, 7, 12, 10, 14, 17,
464 0, 0, 0, 0, 22, 8, 13, 15, 28, 29,
465 30, 26, 25, 27, 0, 23
468 /* YYDEFGOTO[NTERM-NUM]. */
469 static const yysigned_char yydefgoto[] =
471 -1, 1, 2, 11, 12, 41, 13, 16, 42, 43,
472 34, 23, 35, 54, 31, 14, 15
475 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
477 #define YYPACT_NINF -39
478 static const yysigned_char yypact[] =
480 -39, 5, 28, -39, -39, -39, -39, -39, -39, -39,
481 64, -39, 59, -39, -1, 8, 28, -8, -39, -39,
482 -39, -39, -39, -39, -39, -39, -39, -39, -39, -39,
483 -39, -39, 50, 64, 28, -5, -5, -39, -39, 68,
484 64, 28, 28, 28, 37, -39, -39, 68, -39, -39,
485 -39, -39, -39, -39, 64, -39
488 /* YYPGOTO[NTERM-NUM]. */
489 static const yysigned_char yypgoto[] =
491 -39, -39, -39, -39, -15, -39, -38, -39, -39, -39,
492 -39, -39, -17, -39, -39, -39, -10
495 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
496 positive, shift that token. If negative, reduce the rule which
497 number is the opposite. If zero, do what YYDEFACT says.
498 If YYTABLE_NINF, syntax error. */
499 #define YYTABLE_NINF -39
500 static const yysigned_char yytable[] =
502 17, 32, 24, 45, 46, 3, 33, 25, 26, 27,
503 40, -38, 28, 29, 36, 30, -38, -38, -38, 39,
504 0, -38, -38, 38, -38, 0, 0, 0, 47, 0,
505 44, 4, 5, 6, 7, 8, 0, 0, 0, 9,
506 0, 10, 0, 0, 55, 48, 49, 50, 0, 0,
507 51, 52, 0, 53, 19, 20, 21, 22, 0, -4,
508 18, 0, 37, 19, 20, 21, 22, 4, 5, 6,
512 static const yysigned_char yycheck[] =
514 10, 16, 3, 41, 42, 0, 14, 8, 9, 10,
515 15, 3, 13, 14, 31, 16, 8, 9, 10, 34,
516 -1, 13, 14, 33, 16, -1, -1, -1, 43, -1,
517 40, 3, 4, 5, 6, 7, -1, -1, -1, 11,
518 -1, 13, -1, -1, 54, 8, 9, 10, -1, -1,
519 13, 14, -1, 16, 4, 5, 6, 7, -1, 0,
520 1, -1, 12, 4, 5, 6, 7, 3, 4, 5,
524 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
525 symbol of state STATE-NUM. */
526 static const unsigned char yystos[] =
528 0, 18, 19, 0, 3, 4, 5, 6, 7, 11,
529 13, 20, 21, 23, 32, 33, 24, 33, 1, 4,
530 5, 6, 7, 28, 3, 8, 9, 10, 13, 14,
531 16, 31, 21, 14, 27, 29, 29, 12, 33, 21,
532 15, 22, 25, 26, 33, 23, 23, 21, 8, 9,
533 10, 13, 14, 16, 30, 33
536 #define yyerrok (yyerrstatus = 0)
537 #define yyclearin (yychar = YYEMPTY)
541 #define YYACCEPT goto yyacceptlab
542 #define YYABORT goto yyabortlab
543 #define YYERROR goto yyerrorlab
546 /* Like YYERROR except do call yyerror. This remains here temporarily
547 to ease the transition to the new meaning of YYERROR, for GCC.
548 Once GCC version 2 has supplanted version 1, this can go. */
550 #define YYFAIL goto yyerrlab
552 #define YYRECOVERING() (!!yyerrstatus)
554 #define YYBACKUP(Token, Value) \
556 if (yychar == YYEMPTY && yylen == 1) \
560 yytoken = YYTRANSLATE (yychar); \
566 yyerror (YY_("syntax error: cannot back up")); \
573 #define YYERRCODE 256
576 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
577 If N is 0, then set CURRENT to the empty location which ends
578 the previous symbol: RHS[0] (always defined). */
580 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
581 #ifndef YYLLOC_DEFAULT
582 # define YYLLOC_DEFAULT(Current, Rhs, N) \
586 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
587 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
588 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
589 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
593 (Current).first_line = (Current).last_line = \
594 YYRHSLOC (Rhs, 0).last_line; \
595 (Current).first_column = (Current).last_column = \
596 YYRHSLOC (Rhs, 0).last_column; \
602 /* YY_LOCATION_PRINT -- Print the location on the stream.
603 This macro was not mandated originally: define only if we know
604 we won't break user code: when these are the locations we know. */
606 #ifndef YY_LOCATION_PRINT
607 # if YYLTYPE_IS_TRIVIAL
608 # define YY_LOCATION_PRINT(File, Loc) \
609 fprintf (File, "%d.%d-%d.%d", \
610 (Loc).first_line, (Loc).first_column, \
611 (Loc).last_line, (Loc).last_column)
613 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
618 /* YYLEX -- calling `yylex' with the right arguments. */
621 # define YYLEX yylex (&yylval, YYLEX_PARAM)
623 # define YYLEX yylex (&yylval)
626 /* Enable debugging if requested. */
630 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
631 # define YYFPRINTF fprintf
634 # define YYDPRINTF(Args) \
640 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
644 YYFPRINTF (stderr, "%s ", Title); \
645 yysymprint (stderr, \
647 YYFPRINTF (stderr, "\n"); \
651 /*------------------------------------------------------------------.
652 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
654 `------------------------------------------------------------------*/
656 #if defined (__STDC__) || defined (__cplusplus)
658 yy_stack_print (short int *bottom, short int *top)
661 yy_stack_print (bottom, top)
666 YYFPRINTF (stderr, "Stack now");
667 for (/* Nothing. */; bottom <= top; ++bottom)
668 YYFPRINTF (stderr, " %d", *bottom);
669 YYFPRINTF (stderr, "\n");
672 # define YY_STACK_PRINT(Bottom, Top) \
675 yy_stack_print ((Bottom), (Top)); \
679 /*------------------------------------------------.
680 | Report that the YYRULE is going to be reduced. |
681 `------------------------------------------------*/
683 #if defined (__STDC__) || defined (__cplusplus)
685 yy_reduce_print (int yyrule)
688 yy_reduce_print (yyrule)
693 unsigned long int yylno = yyrline[yyrule];
694 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ",
696 /* Print the symbols being reduced, and their result. */
697 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
698 YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
699 YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]);
702 # define YY_REDUCE_PRINT(Rule) \
705 yy_reduce_print (Rule); \
708 /* Nonzero means print parse trace. It is left uninitialized so that
709 multiple parsers can coexist. */
712 # define YYDPRINTF(Args)
713 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
714 # define YY_STACK_PRINT(Bottom, Top)
715 # define YY_REDUCE_PRINT(Rule)
716 #endif /* !YYDEBUG */
719 /* YYINITDEPTH -- initial size of the parser's stacks. */
721 # define YYINITDEPTH 200
724 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
725 if the built-in stack extension method is used).
727 Do not make this value too large; the results are undefined if
728 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
729 evaluated with infinite-precision integer arithmetic. */
732 # define YYMAXDEPTH 10000
740 # if defined (__GLIBC__) && defined (_STRING_H)
741 # define yystrlen strlen
743 /* Return the length of YYSTR. */
745 # if defined (__STDC__) || defined (__cplusplus)
746 yystrlen (const char *yystr)
752 const char *yys = yystr;
754 while (*yys++ != '\0')
757 return yys - yystr - 1;
763 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
764 # define yystpcpy stpcpy
766 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
769 # if defined (__STDC__) || defined (__cplusplus)
770 yystpcpy (char *yydest, const char *yysrc)
772 yystpcpy (yydest, yysrc)
778 const char *yys = yysrc;
780 while ((*yyd++ = *yys++) != '\0')
789 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
790 quotes and backslashes, so that it's suitable for yyerror. The
791 heuristic is that double-quoting is unnecessary unless the string
792 contains an apostrophe, a comma, or backslash (other than
793 backslash-backslash). YYSTR is taken from yytname. If YYRES is
794 null, do not copy; instead, return the length of what the result
797 yytnamerr (char *yyres, const char *yystr)
802 char const *yyp = yystr;
809 goto do_not_strip_quotes;
813 goto do_not_strip_quotes;
826 do_not_strip_quotes: ;
830 return yystrlen (yystr);
832 return yystpcpy (yyres, yystr) - yyres;
836 #endif /* YYERROR_VERBOSE */
841 /*--------------------------------.
842 | Print this symbol on YYOUTPUT. |
843 `--------------------------------*/
845 #if defined (__STDC__) || defined (__cplusplus)
847 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
850 yysymprint (yyoutput, yytype, yyvaluep)
856 /* Pacify ``unused variable'' warnings. */
859 if (yytype < YYNTOKENS)
860 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
862 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
866 if (yytype < YYNTOKENS)
867 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
874 YYFPRINTF (yyoutput, ")");
877 #endif /* ! YYDEBUG */
878 /*-----------------------------------------------.
879 | Release the memory associated to this symbol. |
880 `-----------------------------------------------*/
882 #if defined (__STDC__) || defined (__cplusplus)
884 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
887 yydestruct (yymsg, yytype, yyvaluep)
893 /* Pacify ``unused variable'' warnings. */
898 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
909 /* Prevent warnings from -Wmissing-prototypes. */
912 # if defined (__STDC__) || defined (__cplusplus)
913 int yyparse (void *YYPARSE_PARAM);
917 #else /* ! YYPARSE_PARAM */
918 #if defined (__STDC__) || defined (__cplusplus)
923 #endif /* ! YYPARSE_PARAM */
935 # if defined (__STDC__) || defined (__cplusplus)
936 int yyparse (void *YYPARSE_PARAM)
938 int yyparse (YYPARSE_PARAM)
941 #else /* ! YYPARSE_PARAM */
942 #if defined (__STDC__) || defined (__cplusplus)
952 /* The look-ahead symbol. */
955 /* The semantic value of the look-ahead symbol. */
958 /* Number of syntax errors so far. */
964 /* Number of tokens to shift before error messages enabled. */
966 /* Look-ahead token as an internal (translated) token number. */
969 /* Three stacks and their tools:
970 `yyss': related to states,
971 `yyvs': related to semantic values,
972 `yyls': related to locations.
974 Refer to the stacks thru separate pointers, to allow yyoverflow
975 to reallocate them elsewhere. */
977 /* The state stack. */
978 short int yyssa[YYINITDEPTH];
979 short int *yyss = yyssa;
982 /* The semantic value stack. */
983 YYSTYPE yyvsa[YYINITDEPTH];
984 YYSTYPE *yyvs = yyvsa;
989 #define YYPOPSTACK (yyvsp--, yyssp--)
991 YYSIZE_T yystacksize = YYINITDEPTH;
993 /* The variables used to return semantic value and location from the
998 /* When reducing, the number of symbols on the RHS of the reduced
1002 YYDPRINTF ((stderr, "Starting parse\n"));
1007 yychar = YYEMPTY; /* Cause a token to be read. */
1009 /* Initialize stack pointers.
1010 Waste one element of value and location stack
1011 so that they stay on the same level as the state stack.
1012 The wasted elements are never initialized. */
1019 /*------------------------------------------------------------.
1020 | yynewstate -- Push a new state, which is found in yystate. |
1021 `------------------------------------------------------------*/
1023 /* In all cases, when you get here, the value and location stacks
1024 have just been pushed. so pushing a state here evens the stacks.
1031 if (yyss + yystacksize - 1 <= yyssp)
1033 /* Get the current used size of the three stacks, in elements. */
1034 YYSIZE_T yysize = yyssp - yyss + 1;
1038 /* Give user a chance to reallocate the stack. Use copies of
1039 these so that the &'s don't force the real ones into
1041 YYSTYPE *yyvs1 = yyvs;
1042 short int *yyss1 = yyss;
1045 /* Each stack pointer address is followed by the size of the
1046 data in use in that stack, in bytes. This used to be a
1047 conditional around just the two extra args, but that might
1048 be undefined if yyoverflow is a macro. */
1049 yyoverflow (YY_("memory exhausted"),
1050 &yyss1, yysize * sizeof (*yyssp),
1051 &yyvs1, yysize * sizeof (*yyvsp),
1058 #else /* no yyoverflow */
1059 # ifndef YYSTACK_RELOCATE
1060 goto yyexhaustedlab;
1062 /* Extend the stack our own way. */
1063 if (YYMAXDEPTH <= yystacksize)
1064 goto yyexhaustedlab;
1066 if (YYMAXDEPTH < yystacksize)
1067 yystacksize = YYMAXDEPTH;
1070 short int *yyss1 = yyss;
1071 union yyalloc *yyptr =
1072 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1074 goto yyexhaustedlab;
1075 YYSTACK_RELOCATE (yyss);
1076 YYSTACK_RELOCATE (yyvs);
1078 # undef YYSTACK_RELOCATE
1080 YYSTACK_FREE (yyss1);
1083 #endif /* no yyoverflow */
1085 yyssp = yyss + yysize - 1;
1086 yyvsp = yyvs + yysize - 1;
1089 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1090 (unsigned long int) yystacksize));
1092 if (yyss + yystacksize - 1 <= yyssp)
1096 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1105 /* Do appropriate processing given the current state. */
1106 /* Read a look-ahead token if we need one and don't already have one. */
1109 /* First try to decide what to do without reference to look-ahead token. */
1111 yyn = yypact[yystate];
1112 if (yyn == YYPACT_NINF)
1115 /* Not known => get a look-ahead token if don't already have one. */
1117 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1118 if (yychar == YYEMPTY)
1120 YYDPRINTF ((stderr, "Reading a token: "));
1124 if (yychar <= YYEOF)
1126 yychar = yytoken = YYEOF;
1127 YYDPRINTF ((stderr, "Now at end of input.\n"));
1131 yytoken = YYTRANSLATE (yychar);
1132 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1135 /* If the proper action on seeing token YYTOKEN is to reduce or to
1136 detect an error, take that action. */
1138 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1143 if (yyn == 0 || yyn == YYTABLE_NINF)
1152 /* Shift the look-ahead token. */
1153 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1155 /* Discard the token being shifted unless it is eof. */
1156 if (yychar != YYEOF)
1162 /* Count tokens shifted since error; after three, turn off error
1171 /*-----------------------------------------------------------.
1172 | yydefault -- do the default action for the current state. |
1173 `-----------------------------------------------------------*/
1175 yyn = yydefact[yystate];
1181 /*-----------------------------.
1182 | yyreduce -- Do a reduction. |
1183 `-----------------------------*/
1185 /* yyn is the number of a rule to reduce with. */
1188 /* If YYLEN is nonzero, implement the default value of the action:
1191 Otherwise, the following line sets YYVAL to garbage.
1192 This behavior is undocumented and Bison
1193 users should not rely upon it. Assigning to YYVAL
1194 unconditionally makes the parser a bit smaller, and it avoids a
1195 GCC warning that YYVAL may be used uninitialized. */
1196 yyval = yyvsp[1-yylen];
1199 YY_REDUCE_PRINT (yyn);
1205 (yyval).rel = cql_node_mk_sc(((CQL_parser) parm)->nmem,
1206 "cql.serverChoice", "scr", 0);
1207 ((CQL_parser) parm)->top = 0;
1214 cql_node_destroy((yyval).rel);
1215 ((CQL_parser) parm)->top = (yyvsp[0]).cql;
1222 cql_node_destroy((yyvsp[-1]).cql);
1230 (yyval).rel = (yyvsp[-3]).rel;
1237 struct cql_node *cn = cql_node_mk_boolean(((CQL_parser) parm)->nmem,
1240 cn->u.boolean.modifiers = (yyvsp[-2]).cql;
1241 cn->u.boolean.left = (yyvsp[-4]).cql;
1242 cn->u.boolean.right = (yyvsp[0]).cql;
1251 (yyval).rel = (yyvsp[-1]).rel;
1259 (yyval).cql = (yyvsp[-1]).cql;
1266 struct cql_node *st = cql_node_dup (((CQL_parser) parm)->nmem, (yyvsp[-1]).rel);
1267 st->u.st.term = nmem_strdup(((CQL_parser)parm)->nmem, (yyvsp[0]).buf);
1275 (yyval).rel = cql_node_mk_sc(((CQL_parser) parm)->nmem, (yyvsp[-2]).buf, (yyvsp[-1]).buf, 0);
1276 (yyval).rel->u.st.modifiers = (yyvsp[0]).cql;
1283 (yyval).cql = (yyvsp[0]).cql;
1284 cql_node_destroy((yyvsp[-1]).rel);
1291 (yyval).rel = (yyvsp[-4]).rel;
1298 (yyval).cql = cql_apply_prefix(((CQL_parser) parm)->nmem,
1299 (yyvsp[0]).cql, (yyvsp[-4]).buf, (yyvsp[-2]).buf);
1306 (yyval).rel = (yyvsp[-2]).rel;
1313 (yyval).cql = cql_apply_prefix(((CQL_parser) parm)->nmem,
1314 (yyvsp[0]).cql, 0, (yyvsp[-2]).buf);
1321 struct cql_node *mod = cql_node_mk_sc(((CQL_parser)parm)->nmem,
1322 (yyvsp[0]).buf, "=", 0);
1324 mod->u.st.modifiers = (yyvsp[-2]).cql;
1332 struct cql_node *mod = cql_node_mk_sc(((CQL_parser)parm)->nmem,
1333 (yyvsp[-2]).buf, (yyvsp[-1]).buf, (yyvsp[0]).buf);
1335 mod->u.st.modifiers = (yyvsp[-4]).cql;
1351 /* Line 1126 of yacc.c. */
1358 YY_STACK_PRINT (yyss, yyssp);
1363 /* Now `shift' the result of the reduction. Determine what state
1364 that goes to, based on the state we popped back to and the rule
1365 number reduced by. */
1369 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1370 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1371 yystate = yytable[yystate];
1373 yystate = yydefgoto[yyn - YYNTOKENS];
1378 /*------------------------------------.
1379 | yyerrlab -- here on detecting error |
1380 `------------------------------------*/
1382 /* If not already recovering from an error, report this error. */
1387 yyn = yypact[yystate];
1389 if (YYPACT_NINF < yyn && yyn < YYLAST)
1391 int yytype = YYTRANSLATE (yychar);
1392 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1393 YYSIZE_T yysize = yysize0;
1395 int yysize_overflow = 0;
1397 # define YYERROR_VERBOSE_ARGS_MAXIMUM 5
1398 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1402 /* This is so xgettext sees the translatable formats that are
1403 constructed on the fly. */
1404 YY_("syntax error, unexpected %s");
1405 YY_("syntax error, unexpected %s, expecting %s");
1406 YY_("syntax error, unexpected %s, expecting %s or %s");
1407 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1408 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1412 static char const yyunexpected[] = "syntax error, unexpected %s";
1413 static char const yyexpecting[] = ", expecting %s";
1414 static char const yyor[] = " or %s";
1415 char yyformat[sizeof yyunexpected
1416 + sizeof yyexpecting - 1
1417 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1418 * (sizeof yyor - 1))];
1419 char const *yyprefix = yyexpecting;
1421 /* Start YYX at -YYN if negative to avoid negative indexes in
1423 int yyxbegin = yyn < 0 ? -yyn : 0;
1425 /* Stay within bounds of both yycheck and yytname. */
1426 int yychecklim = YYLAST - yyn;
1427 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1430 yyarg[0] = yytname[yytype];
1431 yyfmt = yystpcpy (yyformat, yyunexpected);
1433 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1434 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1436 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1440 yyformat[sizeof yyunexpected - 1] = '\0';
1443 yyarg[yycount++] = yytname[yyx];
1444 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1445 yysize_overflow |= yysize1 < yysize;
1447 yyfmt = yystpcpy (yyfmt, yyprefix);
1451 yyf = YY_(yyformat);
1452 yysize1 = yysize + yystrlen (yyf);
1453 yysize_overflow |= yysize1 < yysize;
1456 if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM)
1457 yymsg = (char *) YYSTACK_ALLOC (yysize);
1460 /* Avoid sprintf, as that infringes on the user's name space.
1461 Don't have undefined behavior even if the translation
1462 produced a string with the wrong number of "%s"s. */
1465 while ((*yyp = *yyf))
1467 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1469 yyp += yytnamerr (yyp, yyarg[yyi++]);
1479 YYSTACK_FREE (yymsg);
1483 yyerror (YY_("syntax error"));
1484 goto yyexhaustedlab;
1488 #endif /* YYERROR_VERBOSE */
1489 yyerror (YY_("syntax error"));
1494 if (yyerrstatus == 3)
1496 /* If just tried and failed to reuse look-ahead token after an
1497 error, discard it. */
1499 if (yychar <= YYEOF)
1501 /* Return failure if at end of input. */
1502 if (yychar == YYEOF)
1507 yydestruct ("Error: discarding", yytoken, &yylval);
1512 /* Else will try to reuse look-ahead token after shifting the error
1517 /*---------------------------------------------------.
1518 | yyerrorlab -- error raised explicitly by YYERROR. |
1519 `---------------------------------------------------*/
1522 /* Pacify compilers like GCC when the user code never invokes
1523 YYERROR and the label yyerrorlab therefore never appears in user
1534 /*-------------------------------------------------------------.
1535 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1536 `-------------------------------------------------------------*/
1538 yyerrstatus = 3; /* Each real token shifted decrements this. */
1542 yyn = yypact[yystate];
1543 if (yyn != YYPACT_NINF)
1546 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1554 /* Pop the current state because it cannot handle the error token. */
1559 yydestruct ("Error: popping", yystos[yystate], yyvsp);
1562 YY_STACK_PRINT (yyss, yyssp);
1571 /* Shift the error token. */
1572 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1578 /*-------------------------------------.
1579 | yyacceptlab -- YYACCEPT comes here. |
1580 `-------------------------------------*/
1585 /*-----------------------------------.
1586 | yyabortlab -- YYABORT comes here. |
1587 `-----------------------------------*/
1593 /*-------------------------------------------------.
1594 | yyexhaustedlab -- memory exhaustion comes here. |
1595 `-------------------------------------------------*/
1597 yyerror (YY_("memory exhausted"));
1603 if (yychar != YYEOF && yychar != YYEMPTY)
1604 yydestruct ("Cleanup: discarding lookahead",
1606 while (yyssp != yyss)
1608 yydestruct ("Cleanup: popping",
1609 yystos[*yyssp], yyvsp);
1614 YYSTACK_FREE (yyss);
1623 int yyerror(char *s)
1629 * putb is a utility that puts one character to the string
1630 * in current lexical token. This routine deallocates as
1631 * necessary using NMEM.
1634 static void putb(YYSTYPE *lval, CQL_parser cp, int c)
1636 if (lval->len+1 >= lval->size)
1639 nmem_malloc(cp->nmem, (lval->size = lval->len * 2 + 20));
1640 memcpy (nb, lval->buf, lval->len);
1644 lval->buf[lval->len++] = c;
1645 lval->buf[lval->len] = '\0';
1650 * yylex returns next token for Bison to be read. In this
1651 * case one of the CQL terminals are returned.
1653 int yylex(YYSTYPE *lval, void *vp)
1655 CQL_parser cp = (CQL_parser) vp;
1661 lval->buf = (char *) nmem_malloc(cp->nmem, lval->size);
1662 lval->buf[0] = '\0';
1665 c = cp->getbyte(cp->client_data);
1670 } while (isspace(c));
1671 if (strchr("()=></", c))
1677 c1 = cp->getbyte(cp->client_data);
1684 cp->ungetbyte(c1, cp->client_data);
1688 c1 = cp->getbyte(cp->client_data);
1700 cp->ungetbyte(c1, cp->client_data);
1706 while ((c = cp->getbyte(cp->client_data)) != 0 && c != '"')
1709 c = cp->getbyte(cp->client_data);
1717 while ((c = cp->getbyte(cp->client_data)) != 0 &&
1718 !strchr(" \n()=<>/", c))
1721 c = cp->getbyte(cp->client_data);
1725 printf ("got %s\n", lval->buf);
1728 cp->ungetbyte(c, cp->client_data);
1729 if (!cql_strcmp(lval->buf, "and"))
1731 if (!cql_strcmp(lval->buf, "or"))
1733 if (!cql_strcmp(lval->buf, "not"))
1735 if (!cql_strcmp(lval->buf, "prox"))
1742 int cql_parser_stream(CQL_parser cp,
1743 int (*getbyte)(void *client_data),
1744 void (*ungetbyte)(int b, void *client_data),
1747 nmem_reset(cp->nmem);
1748 cp->getbyte = getbyte;
1749 cp->ungetbyte = ungetbyte;
1750 cp->client_data = client_data;
1752 cql_node_destroy(cp->top);
1759 CQL_parser cql_parser_create(void)
1761 CQL_parser cp = (CQL_parser) xmalloc (sizeof(*cp));
1766 cp->client_data = 0;
1769 cp->nmem = nmem_create();
1773 void cql_parser_destroy(CQL_parser cp)
1775 cql_node_destroy(cp->top);
1776 nmem_destroy(cp->nmem);
1780 struct cql_node *cql_parser_result(CQL_parser cp)