Initial commit
[yaz4j-moved-to-github.git] / dependencies / yaz-2.1.28 / src / cql.c
1 /* A Bison parser, made by GNU Bison 2.1.  */
2
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.
5
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)
9    any later version.
10
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.
15
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.  */
20
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.  */
25
26 /* Written by Richard Stallman by simplifying the original so called
27    ``semantic'' parser.  */
28
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.  */
35
36 /* Identify Bison output.  */
37 #define YYBISON 1
38
39 /* Bison version.  */
40 #define YYBISON_VERSION "2.1"
41
42 /* Skeleton name.  */
43 #define YYSKELETON_NAME "yacc.c"
44
45 /* Pure parsers.  */
46 #define YYPURE 1
47
48 /* Using locations.  */
49 #define YYLSP_NEEDED 0
50
51 /* Substitute the variable and function names.  */
52 #define yyparse cql_parse
53 #define yylex   cql_lex
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
59
60
61 /* Tokens.  */
62 #ifndef YYTOKENTYPE
63 # define YYTOKENTYPE
64    /* Put the tokens into the symbol table, so that GDB and other debuggers
65       know about them.  */
66    enum yytokentype {
67      TERM = 258,
68      AND = 259,
69      OR = 260,
70      NOT = 261,
71      PROX = 262,
72      GE = 263,
73      LE = 264,
74      NE = 265
75    };
76 #endif
77 /* Tokens.  */
78 #define TERM 258
79 #define AND 259
80 #define OR 260
81 #define NOT 261
82 #define PROX 262
83 #define GE 263
84 #define LE 264
85 #define NE 265
86
87
88
89
90 /* Copy the first part of user declarations.  */
91 #line 11 "cql.y"
92
93 /** 
94  * \file cql.c
95  * \brief Implements CQL parser.
96  *
97  * This is a YACC parser, but since it must be reentrant, Bison is required.
98  * The original source file is cql.y.
99  */
100 #include <stdio.h>
101 #include <stdlib.h>
102 #include <string.h>
103 #include <ctype.h>
104 #include <yaz/xmalloc.h>
105 #include <yaz/nmem.h>
106 #include <yaz/cql.h>
107
108     /** Node in the LALR parse tree. */
109     typedef struct {
110         /** Inhereted attribute: relation */
111         struct cql_node *rel;
112         /** Synthesized attribute: CQL node */
113         struct cql_node *cql;
114         /** string buffer with token */
115         char *buf;
116         /** length of token */
117         size_t len;
118         /** size of buffer (len <= size) */
119         size_t size;
120     } token;        
121
122     struct cql_parser {
123         int (*getbyte)(void *client_data);
124         void (*ungetbyte)(int b, void *client_data);
125         void *client_data;
126         int last_error;
127         int last_pos;
128         struct cql_node *top;
129         NMEM nmem;
130     };
131
132 #define YYSTYPE token
133     
134 #define YYPARSE_PARAM parm
135 #define YYLEX_PARAM parm
136     
137     int yylex(YYSTYPE *lval, void *vp);
138     int yyerror(char *s);
139
140
141 /* Enabling traces.  */
142 #ifndef YYDEBUG
143 # define YYDEBUG 0
144 #endif
145
146 /* Enabling verbose error messages.  */
147 #ifdef YYERROR_VERBOSE
148 # undef YYERROR_VERBOSE
149 # define YYERROR_VERBOSE 1
150 #else
151 # define YYERROR_VERBOSE 0
152 #endif
153
154 /* Enabling the token table.  */
155 #ifndef YYTOKEN_TABLE
156 # define YYTOKEN_TABLE 0
157 #endif
158
159 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
160 typedef int YYSTYPE;
161 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
162 # define YYSTYPE_IS_DECLARED 1
163 # define YYSTYPE_IS_TRIVIAL 1
164 #endif
165
166
167
168 /* Copy the second part of user declarations.  */
169
170
171 /* Line 219 of yacc.c.  */
172 #line 173 "cql.c"
173
174 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
175 # define YYSIZE_T __SIZE_TYPE__
176 #endif
177 #if ! defined (YYSIZE_T) && defined (size_t)
178 # define YYSIZE_T size_t
179 #endif
180 #if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
181 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
182 # define YYSIZE_T size_t
183 #endif
184 #if ! defined (YYSIZE_T)
185 # define YYSIZE_T unsigned int
186 #endif
187
188 #ifndef YY_
189 # if YYENABLE_NLS
190 #  if ENABLE_NLS
191 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
192 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
193 #  endif
194 # endif
195 # ifndef YY_
196 #  define YY_(msgid) msgid
197 # endif
198 #endif
199
200 #if ! defined (yyoverflow) || YYERROR_VERBOSE
201
202 /* The parser invokes alloca or malloc; define the necessary symbols.  */
203
204 # ifdef YYSTACK_USE_ALLOCA
205 #  if YYSTACK_USE_ALLOCA
206 #   ifdef __GNUC__
207 #    define YYSTACK_ALLOC __builtin_alloca
208 #   else
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
213 #    endif
214 #   endif
215 #  endif
216 # endif
217
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 */
227 #  endif
228 # else
229 #  define YYSTACK_ALLOC YYMALLOC
230 #  define YYSTACK_FREE YYFREE
231 #  ifndef YYSTACK_ALLOC_MAXIMUM
232 #   define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1)
233 #  endif
234 #  ifdef __cplusplus
235 extern "C" {
236 #  endif
237 #  ifndef YYMALLOC
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 */
242 #   endif
243 #  endif
244 #  ifndef YYFREE
245 #   define YYFREE free
246 #   if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \
247         && (defined (__STDC__) || defined (__cplusplus)))
248 void free (void *); /* INFRINGES ON USER NAME SPACE */
249 #   endif
250 #  endif
251 #  ifdef __cplusplus
252 }
253 #  endif
254 # endif
255 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
256
257
258 #if (! defined (yyoverflow) \
259      && (! defined (__cplusplus) \
260          || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
261
262 /* A type that is properly aligned for any stack member.  */
263 union yyalloc
264 {
265   short int yyss;
266   YYSTYPE yyvs;
267   };
268
269 /* The size of the maximum gap between one aligned stack and the next.  */
270 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
271
272 /* The size of an array large to enough to hold all stacks, each with
273    N elements.  */
274 # define YYSTACK_BYTES(N) \
275      ((N) * (sizeof (short int) + sizeof (YYSTYPE))                     \
276       + YYSTACK_GAP_MAXIMUM)
277
278 /* Copy COUNT objects from FROM to TO.  The source and destination do
279    not overlap.  */
280 # ifndef YYCOPY
281 #  if defined (__GNUC__) && 1 < __GNUC__
282 #   define YYCOPY(To, From, Count) \
283       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
284 #  else
285 #   define YYCOPY(To, From, Count)              \
286       do                                        \
287         {                                       \
288           YYSIZE_T yyi;                         \
289           for (yyi = 0; yyi < (Count); yyi++)   \
290             (To)[yyi] = (From)[yyi];            \
291         }                                       \
292       while (0)
293 #  endif
294 # endif
295
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
300    stack.  */
301 # define YYSTACK_RELOCATE(Stack)                                        \
302     do                                                                  \
303       {                                                                 \
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);                          \
309       }                                                                 \
310     while (0)
311
312 #endif
313
314 #if defined (__STDC__) || defined (__cplusplus)
315    typedef signed char yysigned_char;
316 #else
317    typedef short int yysigned_char;
318 #endif
319
320 /* YYFINAL -- State number of the termination state. */
321 #define YYFINAL  3
322 /* YYLAST -- Last index in YYTABLE.  */
323 #define YYLAST   75
324
325 /* YYNTOKENS -- Number of terminals. */
326 #define YYNTOKENS  17
327 /* YYNNTS -- Number of nonterminals. */
328 #define YYNNTS  17
329 /* YYNRULES -- Number of rules. */
330 #define YYNRULES  43
331 /* YYNRULES -- Number of states. */
332 #define YYNSTATES  56
333
334 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
335 #define YYUNDEFTOK  2
336 #define YYMAXUTOK   265
337
338 #define YYTRANSLATE(YYX)                                                \
339   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
340
341 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
342 static const unsigned char yytranslate[] =
343 {
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,
370        5,     6,     7,     8,     9,    10
371 };
372
373 #if YYDEBUG
374 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
375    YYRHS.  */
376 static const unsigned char yyprhs[] =
377 {
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,
382       99,   101,   103,   105
383 };
384
385 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
386 static const yysigned_char yyrhs[] =
387 {
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
399 };
400
401 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
402 static const unsigned char yyrline[] =
403 {
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,
408      188,   189,   190,   191
409 };
410 #endif
411
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[] =
416 {
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",
421   "searchTerm", 0
422 };
423 #endif
424
425 # ifdef YYPRINT
426 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
427    token YYLEX-NUM.  */
428 static const unsigned short int yytoknum[] =
429 {
430        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
431      265,    40,    41,    62,    61,    47,    60
432 };
433 # endif
434
435 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
436 static const unsigned char yyr1[] =
437 {
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,
442       33,    33,    33,    33
443 };
444
445 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
446 static const unsigned char yyr2[] =
447 {
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,
452        1,     1,     1,     1
453 };
454
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[] =
459 {
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
466 };
467
468 /* YYDEFGOTO[NTERM-NUM]. */
469 static const yysigned_char yydefgoto[] =
470 {
471       -1,     1,     2,    11,    12,    41,    13,    16,    42,    43,
472       34,    23,    35,    54,    31,    14,    15
473 };
474
475 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
476    STATE-NUM.  */
477 #define YYPACT_NINF -39
478 static const yysigned_char yypact[] =
479 {
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
486 };
487
488 /* YYPGOTO[NTERM-NUM].  */
489 static const yysigned_char yypgoto[] =
490 {
491      -39,   -39,   -39,   -39,   -15,   -39,   -38,   -39,   -39,   -39,
492      -39,   -39,   -17,   -39,   -39,   -39,   -10
493 };
494
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[] =
501 {
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,
509        7,     8,    19,    20,    21,    22
510 };
511
512 static const yysigned_char yycheck[] =
513 {
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,
521        6,     7,     4,     5,     6,     7
522 };
523
524 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
525    symbol of state STATE-NUM.  */
526 static const unsigned char yystos[] =
527 {
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
534 };
535
536 #define yyerrok         (yyerrstatus = 0)
537 #define yyclearin       (yychar = YYEMPTY)
538 #define YYEMPTY         (-2)
539 #define YYEOF           0
540
541 #define YYACCEPT        goto yyacceptlab
542 #define YYABORT         goto yyabortlab
543 #define YYERROR         goto yyerrorlab
544
545
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.  */
549
550 #define YYFAIL          goto yyerrlab
551
552 #define YYRECOVERING()  (!!yyerrstatus)
553
554 #define YYBACKUP(Token, Value)                                  \
555 do                                                              \
556   if (yychar == YYEMPTY && yylen == 1)                          \
557     {                                                           \
558       yychar = (Token);                                         \
559       yylval = (Value);                                         \
560       yytoken = YYTRANSLATE (yychar);                           \
561       YYPOPSTACK;                                               \
562       goto yybackup;                                            \
563     }                                                           \
564   else                                                          \
565     {                                                           \
566       yyerror (YY_("syntax error: cannot back up")); \
567       YYERROR;                                                  \
568     }                                                           \
569 while (0)
570
571
572 #define YYTERROR        1
573 #define YYERRCODE       256
574
575
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).  */
579
580 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
581 #ifndef YYLLOC_DEFAULT
582 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
583     do                                                                  \
584       if (N)                                                            \
585         {                                                               \
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;       \
590         }                                                               \
591       else                                                              \
592         {                                                               \
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;                              \
597         }                                                               \
598     while (0)
599 #endif
600
601
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.  */
605
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)
612 # else
613 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
614 # endif
615 #endif
616
617
618 /* YYLEX -- calling `yylex' with the right arguments.  */
619
620 #ifdef YYLEX_PARAM
621 # define YYLEX yylex (&yylval, YYLEX_PARAM)
622 #else
623 # define YYLEX yylex (&yylval)
624 #endif
625
626 /* Enable debugging if requested.  */
627 #if YYDEBUG
628
629 # ifndef YYFPRINTF
630 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
631 #  define YYFPRINTF fprintf
632 # endif
633
634 # define YYDPRINTF(Args)                        \
635 do {                                            \
636   if (yydebug)                                  \
637     YYFPRINTF Args;                             \
638 } while (0)
639
640 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)          \
641 do {                                                            \
642   if (yydebug)                                                  \
643     {                                                           \
644       YYFPRINTF (stderr, "%s ", Title);                         \
645       yysymprint (stderr,                                       \
646                   Type, Value); \
647       YYFPRINTF (stderr, "\n");                                 \
648     }                                                           \
649 } while (0)
650
651 /*------------------------------------------------------------------.
652 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
653 | TOP (included).                                                   |
654 `------------------------------------------------------------------*/
655
656 #if defined (__STDC__) || defined (__cplusplus)
657 static void
658 yy_stack_print (short int *bottom, short int *top)
659 #else
660 static void
661 yy_stack_print (bottom, top)
662     short int *bottom;
663     short int *top;
664 #endif
665 {
666   YYFPRINTF (stderr, "Stack now");
667   for (/* Nothing. */; bottom <= top; ++bottom)
668     YYFPRINTF (stderr, " %d", *bottom);
669   YYFPRINTF (stderr, "\n");
670 }
671
672 # define YY_STACK_PRINT(Bottom, Top)                            \
673 do {                                                            \
674   if (yydebug)                                                  \
675     yy_stack_print ((Bottom), (Top));                           \
676 } while (0)
677
678
679 /*------------------------------------------------.
680 | Report that the YYRULE is going to be reduced.  |
681 `------------------------------------------------*/
682
683 #if defined (__STDC__) || defined (__cplusplus)
684 static void
685 yy_reduce_print (int yyrule)
686 #else
687 static void
688 yy_reduce_print (yyrule)
689     int yyrule;
690 #endif
691 {
692   int yyi;
693   unsigned long int yylno = yyrline[yyrule];
694   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ",
695              yyrule - 1, yylno);
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]]);
700 }
701
702 # define YY_REDUCE_PRINT(Rule)          \
703 do {                                    \
704   if (yydebug)                          \
705     yy_reduce_print (Rule);             \
706 } while (0)
707
708 /* Nonzero means print parse trace.  It is left uninitialized so that
709    multiple parsers can coexist.  */
710 int yydebug;
711 #else /* !YYDEBUG */
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 */
717
718
719 /* YYINITDEPTH -- initial size of the parser's stacks.  */
720 #ifndef YYINITDEPTH
721 # define YYINITDEPTH 200
722 #endif
723
724 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
725    if the built-in stack extension method is used).
726
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.  */
730
731 #ifndef YYMAXDEPTH
732 # define YYMAXDEPTH 10000
733 #endif
734
735 \f
736
737 #if YYERROR_VERBOSE
738
739 # ifndef yystrlen
740 #  if defined (__GLIBC__) && defined (_STRING_H)
741 #   define yystrlen strlen
742 #  else
743 /* Return the length of YYSTR.  */
744 static YYSIZE_T
745 #   if defined (__STDC__) || defined (__cplusplus)
746 yystrlen (const char *yystr)
747 #   else
748 yystrlen (yystr)
749      const char *yystr;
750 #   endif
751 {
752   const char *yys = yystr;
753
754   while (*yys++ != '\0')
755     continue;
756
757   return yys - yystr - 1;
758 }
759 #  endif
760 # endif
761
762 # ifndef yystpcpy
763 #  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
764 #   define yystpcpy stpcpy
765 #  else
766 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
767    YYDEST.  */
768 static char *
769 #   if defined (__STDC__) || defined (__cplusplus)
770 yystpcpy (char *yydest, const char *yysrc)
771 #   else
772 yystpcpy (yydest, yysrc)
773      char *yydest;
774      const char *yysrc;
775 #   endif
776 {
777   char *yyd = yydest;
778   const char *yys = yysrc;
779
780   while ((*yyd++ = *yys++) != '\0')
781     continue;
782
783   return yyd - 1;
784 }
785 #  endif
786 # endif
787
788 # ifndef yytnamerr
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
795    would have been.  */
796 static YYSIZE_T
797 yytnamerr (char *yyres, const char *yystr)
798 {
799   if (*yystr == '"')
800     {
801       size_t yyn = 0;
802       char const *yyp = yystr;
803
804       for (;;)
805         switch (*++yyp)
806           {
807           case '\'':
808           case ',':
809             goto do_not_strip_quotes;
810
811           case '\\':
812             if (*++yyp != '\\')
813               goto do_not_strip_quotes;
814             /* Fall through.  */
815           default:
816             if (yyres)
817               yyres[yyn] = *yyp;
818             yyn++;
819             break;
820
821           case '"':
822             if (yyres)
823               yyres[yyn] = '\0';
824             return yyn;
825           }
826     do_not_strip_quotes: ;
827     }
828
829   if (! yyres)
830     return yystrlen (yystr);
831
832   return yystpcpy (yyres, yystr) - yyres;
833 }
834 # endif
835
836 #endif /* YYERROR_VERBOSE */
837
838 \f
839
840 #if YYDEBUG
841 /*--------------------------------.
842 | Print this symbol on YYOUTPUT.  |
843 `--------------------------------*/
844
845 #if defined (__STDC__) || defined (__cplusplus)
846 static void
847 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
848 #else
849 static void
850 yysymprint (yyoutput, yytype, yyvaluep)
851     FILE *yyoutput;
852     int yytype;
853     YYSTYPE *yyvaluep;
854 #endif
855 {
856   /* Pacify ``unused variable'' warnings.  */
857   (void) yyvaluep;
858
859   if (yytype < YYNTOKENS)
860     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
861   else
862     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
863
864
865 # ifdef YYPRINT
866   if (yytype < YYNTOKENS)
867     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
868 # endif
869   switch (yytype)
870     {
871       default:
872         break;
873     }
874   YYFPRINTF (yyoutput, ")");
875 }
876
877 #endif /* ! YYDEBUG */
878 /*-----------------------------------------------.
879 | Release the memory associated to this symbol.  |
880 `-----------------------------------------------*/
881
882 #if defined (__STDC__) || defined (__cplusplus)
883 static void
884 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
885 #else
886 static void
887 yydestruct (yymsg, yytype, yyvaluep)
888     const char *yymsg;
889     int yytype;
890     YYSTYPE *yyvaluep;
891 #endif
892 {
893   /* Pacify ``unused variable'' warnings.  */
894   (void) yyvaluep;
895
896   if (!yymsg)
897     yymsg = "Deleting";
898   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
899
900   switch (yytype)
901     {
902
903       default:
904         break;
905     }
906 }
907 \f
908
909 /* Prevent warnings from -Wmissing-prototypes.  */
910
911 #ifdef YYPARSE_PARAM
912 # if defined (__STDC__) || defined (__cplusplus)
913 int yyparse (void *YYPARSE_PARAM);
914 # else
915 int yyparse ();
916 # endif
917 #else /* ! YYPARSE_PARAM */
918 #if defined (__STDC__) || defined (__cplusplus)
919 int yyparse (void);
920 #else
921 int yyparse ();
922 #endif
923 #endif /* ! YYPARSE_PARAM */
924
925
926
927
928
929
930 /*----------.
931 | yyparse.  |
932 `----------*/
933
934 #ifdef YYPARSE_PARAM
935 # if defined (__STDC__) || defined (__cplusplus)
936 int yyparse (void *YYPARSE_PARAM)
937 # else
938 int yyparse (YYPARSE_PARAM)
939   void *YYPARSE_PARAM;
940 # endif
941 #else /* ! YYPARSE_PARAM */
942 #if defined (__STDC__) || defined (__cplusplus)
943 int
944 yyparse (void)
945 #else
946 int
947 yyparse ()
948     ;
949 #endif
950 #endif
951 {
952   /* The look-ahead symbol.  */
953 int yychar;
954
955 /* The semantic value of the look-ahead symbol.  */
956 YYSTYPE yylval;
957
958 /* Number of syntax errors so far.  */
959 int yynerrs;
960
961   int yystate;
962   int yyn;
963   int yyresult;
964   /* Number of tokens to shift before error messages enabled.  */
965   int yyerrstatus;
966   /* Look-ahead token as an internal (translated) token number.  */
967   int yytoken = 0;
968
969   /* Three stacks and their tools:
970      `yyss': related to states,
971      `yyvs': related to semantic values,
972      `yyls': related to locations.
973
974      Refer to the stacks thru separate pointers, to allow yyoverflow
975      to reallocate them elsewhere.  */
976
977   /* The state stack.  */
978   short int yyssa[YYINITDEPTH];
979   short int *yyss = yyssa;
980   short int *yyssp;
981
982   /* The semantic value stack.  */
983   YYSTYPE yyvsa[YYINITDEPTH];
984   YYSTYPE *yyvs = yyvsa;
985   YYSTYPE *yyvsp;
986
987
988
989 #define YYPOPSTACK   (yyvsp--, yyssp--)
990
991   YYSIZE_T yystacksize = YYINITDEPTH;
992
993   /* The variables used to return semantic value and location from the
994      action routines.  */
995   YYSTYPE yyval;
996
997
998   /* When reducing, the number of symbols on the RHS of the reduced
999      rule.  */
1000   int yylen;
1001
1002   YYDPRINTF ((stderr, "Starting parse\n"));
1003
1004   yystate = 0;
1005   yyerrstatus = 0;
1006   yynerrs = 0;
1007   yychar = YYEMPTY;             /* Cause a token to be read.  */
1008
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.  */
1013
1014   yyssp = yyss;
1015   yyvsp = yyvs;
1016
1017   goto yysetstate;
1018
1019 /*------------------------------------------------------------.
1020 | yynewstate -- Push a new state, which is found in yystate.  |
1021 `------------------------------------------------------------*/
1022  yynewstate:
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.
1025      */
1026   yyssp++;
1027
1028  yysetstate:
1029   *yyssp = yystate;
1030
1031   if (yyss + yystacksize - 1 <= yyssp)
1032     {
1033       /* Get the current used size of the three stacks, in elements.  */
1034       YYSIZE_T yysize = yyssp - yyss + 1;
1035
1036 #ifdef yyoverflow
1037       {
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
1040            memory.  */
1041         YYSTYPE *yyvs1 = yyvs;
1042         short int *yyss1 = yyss;
1043
1044
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),
1052
1053                     &yystacksize);
1054
1055         yyss = yyss1;
1056         yyvs = yyvs1;
1057       }
1058 #else /* no yyoverflow */
1059 # ifndef YYSTACK_RELOCATE
1060       goto yyexhaustedlab;
1061 # else
1062       /* Extend the stack our own way.  */
1063       if (YYMAXDEPTH <= yystacksize)
1064         goto yyexhaustedlab;
1065       yystacksize *= 2;
1066       if (YYMAXDEPTH < yystacksize)
1067         yystacksize = YYMAXDEPTH;
1068
1069       {
1070         short int *yyss1 = yyss;
1071         union yyalloc *yyptr =
1072           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1073         if (! yyptr)
1074           goto yyexhaustedlab;
1075         YYSTACK_RELOCATE (yyss);
1076         YYSTACK_RELOCATE (yyvs);
1077
1078 #  undef YYSTACK_RELOCATE
1079         if (yyss1 != yyssa)
1080           YYSTACK_FREE (yyss1);
1081       }
1082 # endif
1083 #endif /* no yyoverflow */
1084
1085       yyssp = yyss + yysize - 1;
1086       yyvsp = yyvs + yysize - 1;
1087
1088
1089       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1090                   (unsigned long int) yystacksize));
1091
1092       if (yyss + yystacksize - 1 <= yyssp)
1093         YYABORT;
1094     }
1095
1096   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1097
1098   goto yybackup;
1099
1100 /*-----------.
1101 | yybackup.  |
1102 `-----------*/
1103 yybackup:
1104
1105 /* Do appropriate processing given the current state.  */
1106 /* Read a look-ahead token if we need one and don't already have one.  */
1107 /* yyresume: */
1108
1109   /* First try to decide what to do without reference to look-ahead token.  */
1110
1111   yyn = yypact[yystate];
1112   if (yyn == YYPACT_NINF)
1113     goto yydefault;
1114
1115   /* Not known => get a look-ahead token if don't already have one.  */
1116
1117   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
1118   if (yychar == YYEMPTY)
1119     {
1120       YYDPRINTF ((stderr, "Reading a token: "));
1121       yychar = YYLEX;
1122     }
1123
1124   if (yychar <= YYEOF)
1125     {
1126       yychar = yytoken = YYEOF;
1127       YYDPRINTF ((stderr, "Now at end of input.\n"));
1128     }
1129   else
1130     {
1131       yytoken = YYTRANSLATE (yychar);
1132       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1133     }
1134
1135   /* If the proper action on seeing token YYTOKEN is to reduce or to
1136      detect an error, take that action.  */
1137   yyn += yytoken;
1138   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1139     goto yydefault;
1140   yyn = yytable[yyn];
1141   if (yyn <= 0)
1142     {
1143       if (yyn == 0 || yyn == YYTABLE_NINF)
1144         goto yyerrlab;
1145       yyn = -yyn;
1146       goto yyreduce;
1147     }
1148
1149   if (yyn == YYFINAL)
1150     YYACCEPT;
1151
1152   /* Shift the look-ahead token.  */
1153   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1154
1155   /* Discard the token being shifted unless it is eof.  */
1156   if (yychar != YYEOF)
1157     yychar = YYEMPTY;
1158
1159   *++yyvsp = yylval;
1160
1161
1162   /* Count tokens shifted since error; after three, turn off error
1163      status.  */
1164   if (yyerrstatus)
1165     yyerrstatus--;
1166
1167   yystate = yyn;
1168   goto yynewstate;
1169
1170
1171 /*-----------------------------------------------------------.
1172 | yydefault -- do the default action for the current state.  |
1173 `-----------------------------------------------------------*/
1174 yydefault:
1175   yyn = yydefact[yystate];
1176   if (yyn == 0)
1177     goto yyerrlab;
1178   goto yyreduce;
1179
1180
1181 /*-----------------------------.
1182 | yyreduce -- Do a reduction.  |
1183 `-----------------------------*/
1184 yyreduce:
1185   /* yyn is the number of a rule to reduce with.  */
1186   yylen = yyr2[yyn];
1187
1188   /* If YYLEN is nonzero, implement the default value of the action:
1189      `$$ = $1'.
1190
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];
1197
1198
1199   YY_REDUCE_PRINT (yyn);
1200   switch (yyn)
1201     {
1202         case 2:
1203 #line 66 "cql.y"
1204     { 
1205     (yyval).rel = cql_node_mk_sc(((CQL_parser) parm)->nmem,
1206                             "cql.serverChoice", "scr", 0);
1207     ((CQL_parser) parm)->top = 0;
1208 }
1209     break;
1210
1211   case 3:
1212 #line 70 "cql.y"
1213     {
1214     cql_node_destroy((yyval).rel);
1215     ((CQL_parser) parm)->top = (yyvsp[0]).cql; 
1216 }
1217     break;
1218
1219   case 5:
1220 #line 77 "cql.y"
1221     {
1222     cql_node_destroy((yyvsp[-1]).cql);
1223     (yyval).cql = 0;
1224 }
1225     break;
1226
1227   case 7:
1228 #line 86 "cql.y"
1229     { 
1230       (yyval).rel = (yyvsp[-3]).rel;
1231   }
1232     break;
1233
1234   case 8:
1235 #line 88 "cql.y"
1236     {
1237       struct cql_node *cn = cql_node_mk_boolean(((CQL_parser) parm)->nmem,
1238                                                 (yyvsp[-3]).buf);
1239       
1240       cn->u.boolean.modifiers = (yyvsp[-2]).cql;
1241       cn->u.boolean.left = (yyvsp[-4]).cql;
1242       cn->u.boolean.right = (yyvsp[0]).cql;
1243
1244       (yyval).cql = cn;
1245   }
1246     break;
1247
1248   case 9:
1249 #line 101 "cql.y"
1250     { 
1251       (yyval).rel = (yyvsp[-1]).rel;
1252       
1253   }
1254     break;
1255
1256   case 10:
1257 #line 104 "cql.y"
1258     {
1259       (yyval).cql = (yyvsp[-1]).cql;
1260   }
1261     break;
1262
1263   case 11:
1264 #line 108 "cql.y"
1265     {
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);
1268       (yyval).cql = st;
1269   }
1270     break;
1271
1272   case 12:
1273 #line 114 "cql.y"
1274     {
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;
1277   }
1278     break;
1279
1280   case 13:
1281 #line 117 "cql.y"
1282     {
1283       (yyval).cql = (yyvsp[0]).cql;
1284       cql_node_destroy((yyvsp[-1]).rel);
1285   }
1286     break;
1287
1288   case 14:
1289 #line 121 "cql.y"
1290     {
1291       (yyval).rel = (yyvsp[-4]).rel;
1292   }
1293     break;
1294
1295   case 15:
1296 #line 123 "cql.y"
1297     {
1298     (yyval).cql = cql_apply_prefix(((CQL_parser) parm)->nmem,
1299                               (yyvsp[0]).cql, (yyvsp[-4]).buf, (yyvsp[-2]).buf);
1300   }
1301     break;
1302
1303   case 16:
1304 #line 127 "cql.y"
1305     {
1306       (yyval).rel = (yyvsp[-2]).rel;
1307   }
1308     break;
1309
1310   case 17:
1311 #line 129 "cql.y"
1312     {
1313     (yyval).cql = cql_apply_prefix(((CQL_parser) parm)->nmem, 
1314                               (yyvsp[0]).cql, 0, (yyvsp[-2]).buf);
1315    }
1316     break;
1317
1318   case 22:
1319 #line 142 "cql.y"
1320     { 
1321     struct cql_node *mod = cql_node_mk_sc(((CQL_parser)parm)->nmem,
1322                                           (yyvsp[0]).buf, "=", 0);
1323
1324     mod->u.st.modifiers = (yyvsp[-2]).cql;
1325     (yyval).cql = mod;
1326 }
1327     break;
1328
1329   case 23:
1330 #line 151 "cql.y"
1331     {
1332     struct cql_node *mod = cql_node_mk_sc(((CQL_parser)parm)->nmem,
1333                                           (yyvsp[-2]).buf, (yyvsp[-1]).buf, (yyvsp[0]).buf);
1334
1335     mod->u.st.modifiers = (yyvsp[-4]).cql;
1336     (yyval).cql = mod;
1337 }
1338     break;
1339
1340   case 24:
1341 #line 159 "cql.y"
1342     { 
1343     (yyval).cql = 0;
1344 }
1345     break;
1346
1347
1348       default: break;
1349     }
1350
1351 /* Line 1126 of yacc.c.  */
1352 #line 1353 "cql.c"
1353 \f
1354   yyvsp -= yylen;
1355   yyssp -= yylen;
1356
1357
1358   YY_STACK_PRINT (yyss, yyssp);
1359
1360   *++yyvsp = yyval;
1361
1362
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.  */
1366
1367   yyn = yyr1[yyn];
1368
1369   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1370   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1371     yystate = yytable[yystate];
1372   else
1373     yystate = yydefgoto[yyn - YYNTOKENS];
1374
1375   goto yynewstate;
1376
1377
1378 /*------------------------------------.
1379 | yyerrlab -- here on detecting error |
1380 `------------------------------------*/
1381 yyerrlab:
1382   /* If not already recovering from an error, report this error.  */
1383   if (!yyerrstatus)
1384     {
1385       ++yynerrs;
1386 #if YYERROR_VERBOSE
1387       yyn = yypact[yystate];
1388
1389       if (YYPACT_NINF < yyn && yyn < YYLAST)
1390         {
1391           int yytype = YYTRANSLATE (yychar);
1392           YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1393           YYSIZE_T yysize = yysize0;
1394           YYSIZE_T yysize1;
1395           int yysize_overflow = 0;
1396           char *yymsg = 0;
1397 #         define YYERROR_VERBOSE_ARGS_MAXIMUM 5
1398           char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1399           int yyx;
1400
1401 #if 0
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");
1409 #endif
1410           char *yyfmt;
1411           char const *yyf;
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;
1420
1421           /* Start YYX at -YYN if negative to avoid negative indexes in
1422              YYCHECK.  */
1423           int yyxbegin = yyn < 0 ? -yyn : 0;
1424
1425           /* Stay within bounds of both yycheck and yytname.  */
1426           int yychecklim = YYLAST - yyn;
1427           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1428           int yycount = 1;
1429
1430           yyarg[0] = yytname[yytype];
1431           yyfmt = yystpcpy (yyformat, yyunexpected);
1432
1433           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1434             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1435               {
1436                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1437                   {
1438                     yycount = 1;
1439                     yysize = yysize0;
1440                     yyformat[sizeof yyunexpected - 1] = '\0';
1441                     break;
1442                   }
1443                 yyarg[yycount++] = yytname[yyx];
1444                 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1445                 yysize_overflow |= yysize1 < yysize;
1446                 yysize = yysize1;
1447                 yyfmt = yystpcpy (yyfmt, yyprefix);
1448                 yyprefix = yyor;
1449               }
1450
1451           yyf = YY_(yyformat);
1452           yysize1 = yysize + yystrlen (yyf);
1453           yysize_overflow |= yysize1 < yysize;
1454           yysize = yysize1;
1455
1456           if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM)
1457             yymsg = (char *) YYSTACK_ALLOC (yysize);
1458           if (yymsg)
1459             {
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.  */
1463               char *yyp = yymsg;
1464               int yyi = 0;
1465               while ((*yyp = *yyf))
1466                 {
1467                   if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1468                     {
1469                       yyp += yytnamerr (yyp, yyarg[yyi++]);
1470                       yyf += 2;
1471                     }
1472                   else
1473                     {
1474                       yyp++;
1475                       yyf++;
1476                     }
1477                 }
1478               yyerror (yymsg);
1479               YYSTACK_FREE (yymsg);
1480             }
1481           else
1482             {
1483               yyerror (YY_("syntax error"));
1484               goto yyexhaustedlab;
1485             }
1486         }
1487       else
1488 #endif /* YYERROR_VERBOSE */
1489         yyerror (YY_("syntax error"));
1490     }
1491
1492
1493
1494   if (yyerrstatus == 3)
1495     {
1496       /* If just tried and failed to reuse look-ahead token after an
1497          error, discard it.  */
1498
1499       if (yychar <= YYEOF)
1500         {
1501           /* Return failure if at end of input.  */
1502           if (yychar == YYEOF)
1503             YYABORT;
1504         }
1505       else
1506         {
1507           yydestruct ("Error: discarding", yytoken, &yylval);
1508           yychar = YYEMPTY;
1509         }
1510     }
1511
1512   /* Else will try to reuse look-ahead token after shifting the error
1513      token.  */
1514   goto yyerrlab1;
1515
1516
1517 /*---------------------------------------------------.
1518 | yyerrorlab -- error raised explicitly by YYERROR.  |
1519 `---------------------------------------------------*/
1520 yyerrorlab:
1521
1522   /* Pacify compilers like GCC when the user code never invokes
1523      YYERROR and the label yyerrorlab therefore never appears in user
1524      code.  */
1525   if (0)
1526      goto yyerrorlab;
1527
1528 yyvsp -= yylen;
1529   yyssp -= yylen;
1530   yystate = *yyssp;
1531   goto yyerrlab1;
1532
1533
1534 /*-------------------------------------------------------------.
1535 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1536 `-------------------------------------------------------------*/
1537 yyerrlab1:
1538   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1539
1540   for (;;)
1541     {
1542       yyn = yypact[yystate];
1543       if (yyn != YYPACT_NINF)
1544         {
1545           yyn += YYTERROR;
1546           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1547             {
1548               yyn = yytable[yyn];
1549               if (0 < yyn)
1550                 break;
1551             }
1552         }
1553
1554       /* Pop the current state because it cannot handle the error token.  */
1555       if (yyssp == yyss)
1556         YYABORT;
1557
1558
1559       yydestruct ("Error: popping", yystos[yystate], yyvsp);
1560       YYPOPSTACK;
1561       yystate = *yyssp;
1562       YY_STACK_PRINT (yyss, yyssp);
1563     }
1564
1565   if (yyn == YYFINAL)
1566     YYACCEPT;
1567
1568   *++yyvsp = yylval;
1569
1570
1571   /* Shift the error token. */
1572   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1573
1574   yystate = yyn;
1575   goto yynewstate;
1576
1577
1578 /*-------------------------------------.
1579 | yyacceptlab -- YYACCEPT comes here.  |
1580 `-------------------------------------*/
1581 yyacceptlab:
1582   yyresult = 0;
1583   goto yyreturn;
1584
1585 /*-----------------------------------.
1586 | yyabortlab -- YYABORT comes here.  |
1587 `-----------------------------------*/
1588 yyabortlab:
1589   yyresult = 1;
1590   goto yyreturn;
1591
1592 #ifndef yyoverflow
1593 /*-------------------------------------------------.
1594 | yyexhaustedlab -- memory exhaustion comes here.  |
1595 `-------------------------------------------------*/
1596 yyexhaustedlab:
1597   yyerror (YY_("memory exhausted"));
1598   yyresult = 2;
1599   /* Fall through.  */
1600 #endif
1601
1602 yyreturn:
1603   if (yychar != YYEOF && yychar != YYEMPTY)
1604      yydestruct ("Cleanup: discarding lookahead",
1605                  yytoken, &yylval);
1606   while (yyssp != yyss)
1607     {
1608       yydestruct ("Cleanup: popping",
1609                   yystos[*yyssp], yyvsp);
1610       YYPOPSTACK;
1611     }
1612 #ifndef yyoverflow
1613   if (yyss != yyssa)
1614     YYSTACK_FREE (yyss);
1615 #endif
1616   return yyresult;
1617 }
1618
1619
1620 #line 194 "cql.y"
1621
1622
1623 int yyerror(char *s)
1624 {
1625     return 0;
1626 }
1627
1628 /**
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.
1632  */
1633
1634 static void putb(YYSTYPE *lval, CQL_parser cp, int c)
1635 {
1636     if (lval->len+1 >= lval->size)
1637     {
1638         char *nb = (char *)
1639             nmem_malloc(cp->nmem, (lval->size = lval->len * 2 + 20));
1640         memcpy (nb, lval->buf, lval->len);
1641         lval->buf = nb;
1642     }
1643     if (c)
1644         lval->buf[lval->len++] = c;
1645     lval->buf[lval->len] = '\0';
1646 }
1647
1648
1649 /**
1650  * yylex returns next token for Bison to be read. In this
1651  * case one of the CQL terminals are returned.
1652  */
1653 int yylex(YYSTYPE *lval, void *vp)
1654 {
1655     CQL_parser cp = (CQL_parser) vp;
1656     int c;
1657     lval->cql = 0;
1658     lval->rel = 0;
1659     lval->len = 0;
1660     lval->size = 10;
1661     lval->buf = (char *) nmem_malloc(cp->nmem, lval->size);
1662     lval->buf[0] = '\0';
1663     do
1664     {
1665         c = cp->getbyte(cp->client_data);
1666         if (c == 0)
1667             return 0;
1668         if (c == '\n')
1669             return 0;
1670     } while (isspace(c));
1671     if (strchr("()=></", c))
1672     {
1673         int c1;
1674         putb(lval, cp, c);
1675         if (c == '>')
1676         {
1677             c1 = cp->getbyte(cp->client_data);
1678             if (c1 == '=')
1679             {
1680                 putb(lval, cp, c1);
1681                 return GE;
1682             }
1683             else
1684                 cp->ungetbyte(c1, cp->client_data);
1685         }
1686         else if (c == '<')
1687         {
1688             c1 = cp->getbyte(cp->client_data);
1689             if (c1 == '=')
1690             {
1691                 putb(lval, cp, c1);
1692                 return LE;
1693             }
1694             else if (c1 == '>')
1695             {
1696                 putb(lval, cp, c1);
1697                 return NE;
1698             }
1699             else
1700                 cp->ungetbyte(c1, cp->client_data);
1701         }
1702         return c;
1703     }
1704     if (c == '"')
1705     {
1706         while ((c = cp->getbyte(cp->client_data)) != 0 && c != '"')
1707         {
1708             if (c == '\\')
1709                 c = cp->getbyte(cp->client_data);
1710             putb(lval, cp, c);
1711         }
1712         putb(lval, cp, 0);
1713     }
1714     else
1715     {
1716         putb(lval, cp, c);
1717         while ((c = cp->getbyte(cp->client_data)) != 0 &&
1718                !strchr(" \n()=<>/", c))
1719         {
1720             if (c == '\\')
1721                 c = cp->getbyte(cp->client_data);
1722             putb(lval, cp, c);
1723         }
1724 #if YYDEBUG
1725         printf ("got %s\n", lval->buf);
1726 #endif
1727         if (c != 0)
1728             cp->ungetbyte(c, cp->client_data);
1729         if (!cql_strcmp(lval->buf, "and"))
1730             return AND;
1731         if (!cql_strcmp(lval->buf, "or"))
1732             return OR;
1733         if (!cql_strcmp(lval->buf, "not"))
1734             return NOT;
1735         if (!cql_strcmp(lval->buf, "prox"))
1736             return PROX;
1737     }
1738     return TERM;
1739 }
1740
1741
1742 int cql_parser_stream(CQL_parser cp,
1743                       int (*getbyte)(void *client_data),
1744                       void (*ungetbyte)(int b, void *client_data),
1745                       void *client_data)
1746 {
1747     nmem_reset(cp->nmem);
1748     cp->getbyte = getbyte;
1749     cp->ungetbyte = ungetbyte;
1750     cp->client_data = client_data;
1751     if (cp->top)
1752         cql_node_destroy(cp->top);
1753     cql_parse(cp);
1754     if (cp->top)
1755         return 0;
1756     return -1;
1757 }
1758
1759 CQL_parser cql_parser_create(void)
1760 {
1761     CQL_parser cp = (CQL_parser) xmalloc (sizeof(*cp));
1762
1763     cp->top = 0;
1764     cp->getbyte = 0;
1765     cp->ungetbyte = 0;
1766     cp->client_data = 0;
1767     cp->last_error = 0;
1768     cp->last_pos = 0;
1769     cp->nmem = nmem_create();
1770     return cp;
1771 }
1772
1773 void cql_parser_destroy(CQL_parser cp)
1774 {
1775     cql_node_destroy(cp->top);
1776     nmem_destroy(cp->nmem);
1777     xfree (cp);
1778 }
1779
1780 struct cql_node *cql_parser_result(CQL_parser cp)
1781 {
1782     return cp->top;
1783 }
1784
1785