Initial commit
[yaz4j-moved-to-github.git] / dependencies / yaz_3.0.14 / src / cql.c
1 /* A Bison parser, made by GNU Bison 2.3.  */
2
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
4
5    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6    Free Software Foundation, Inc.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2, or (at your option)
11    any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor,
21    Boston, MA 02110-1301, USA.  */
22
23 /* As a special exception, you may create a larger work that contains
24    part or all of the Bison parser skeleton and distribute that work
25    under terms of your choice, so long as that work isn't itself a
26    parser generator using the skeleton or a modified version thereof
27    as a parser skeleton.  Alternatively, if you modify or redistribute
28    the parser skeleton itself, you may (at your option) remove this
29    special exception, which will cause the skeleton and the resulting
30    Bison output files to be licensed under the GNU General Public
31    License without this special exception.
32
33    This special exception was added by the Free Software Foundation in
34    version 2.2 of Bison.  */
35
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37    simplifying the original so-called "semantic" parser.  */
38
39 /* All symbols defined below should begin with yy or YY, to avoid
40    infringing on user name space.  This should be done even for local
41    variables, as they might otherwise be expanded by user macros.
42    There are some unavoidable exceptions within include files to
43    define necessary library symbols; they are noted "INFRINGES ON
44    USER NAME SPACE" below.  */
45
46 /* Identify Bison output.  */
47 #define YYBISON 1
48
49 /* Bison version.  */
50 #define YYBISON_VERSION "2.3"
51
52 /* Skeleton name.  */
53 #define YYSKELETON_NAME "yacc.c"
54
55 /* Pure parsers.  */
56 #define YYPURE 1
57
58 /* Using locations.  */
59 #define YYLSP_NEEDED 0
60
61 /* Substitute the variable and function names.  */
62 #define yyparse cql_parse
63 #define yylex   cql_lex
64 #define yyerror cql_error
65 #define yylval  cql_lval
66 #define yychar  cql_char
67 #define yydebug cql_debug
68 #define yynerrs cql_nerrs
69
70
71 /* Tokens.  */
72 #ifndef YYTOKENTYPE
73 # define YYTOKENTYPE
74    /* Put the tokens into the symbol table, so that GDB and other debuggers
75       know about them.  */
76    enum yytokentype {
77      TERM = 258,
78      AND = 259,
79      OR = 260,
80      NOT = 261,
81      PROX = 262,
82      GE = 263,
83      LE = 264,
84      NE = 265
85    };
86 #endif
87 /* Tokens.  */
88 #define TERM 258
89 #define AND 259
90 #define OR 260
91 #define NOT 261
92 #define PROX 262
93 #define GE 263
94 #define LE 264
95 #define NE 265
96
97
98
99
100 /* Copy the first part of user declarations.  */
101 #line 11 "cql.y"
102
103 /** 
104  * \file cql.c
105  * \brief Implements CQL parser.
106  *
107  * This is a YACC parser, but since it must be reentrant, Bison is required.
108  * The original source file is cql.y.
109  */
110 #include <stdio.h>
111 #include <stdlib.h>
112 #include <string.h>
113 #include <ctype.h>
114 #include <yaz/xmalloc.h>
115 #include <yaz/nmem.h>
116 #include <yaz/cql.h>
117
118     /** Node in the LALR parse tree. */
119     typedef struct {
120         /** Inhereted attribute: relation */
121         struct cql_node *rel;
122         /** Synthesized attribute: CQL node */
123         struct cql_node *cql;
124         /** string buffer with token */
125         char *buf;
126         /** length of token */
127         size_t len;
128         /** size of buffer (len <= size) */
129         size_t size;
130     } token;        
131
132     struct cql_parser {
133         int (*getbyte)(void *client_data);
134         void (*ungetbyte)(int b, void *client_data);
135         void *client_data;
136         int last_error;
137         int last_pos;
138         struct cql_node *top;
139         NMEM nmem;
140     };
141
142 #define YYSTYPE token
143     
144 #define YYPARSE_PARAM parm
145 #define YYLEX_PARAM parm
146     
147     int yylex(YYSTYPE *lval, void *vp);
148     int yyerror(char *s);
149
150
151 /* Enabling traces.  */
152 #ifndef YYDEBUG
153 # define YYDEBUG 0
154 #endif
155
156 /* Enabling verbose error messages.  */
157 #ifdef YYERROR_VERBOSE
158 # undef YYERROR_VERBOSE
159 # define YYERROR_VERBOSE 1
160 #else
161 # define YYERROR_VERBOSE 0
162 #endif
163
164 /* Enabling the token table.  */
165 #ifndef YYTOKEN_TABLE
166 # define YYTOKEN_TABLE 0
167 #endif
168
169 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
170 typedef int YYSTYPE;
171 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
172 # define YYSTYPE_IS_DECLARED 1
173 # define YYSTYPE_IS_TRIVIAL 1
174 #endif
175
176
177
178 /* Copy the second part of user declarations.  */
179
180
181 /* Line 216 of yacc.c.  */
182 #line 183 "cql.c"
183
184 #ifdef short
185 # undef short
186 #endif
187
188 #ifdef YYTYPE_UINT8
189 typedef YYTYPE_UINT8 yytype_uint8;
190 #else
191 typedef unsigned char yytype_uint8;
192 #endif
193
194 #ifdef YYTYPE_INT8
195 typedef YYTYPE_INT8 yytype_int8;
196 #elif (defined __STDC__ || defined __C99__FUNC__ \
197      || defined __cplusplus || defined _MSC_VER)
198 typedef signed char yytype_int8;
199 #else
200 typedef short int yytype_int8;
201 #endif
202
203 #ifdef YYTYPE_UINT16
204 typedef YYTYPE_UINT16 yytype_uint16;
205 #else
206 typedef unsigned short int yytype_uint16;
207 #endif
208
209 #ifdef YYTYPE_INT16
210 typedef YYTYPE_INT16 yytype_int16;
211 #else
212 typedef short int yytype_int16;
213 #endif
214
215 #ifndef YYSIZE_T
216 # ifdef __SIZE_TYPE__
217 #  define YYSIZE_T __SIZE_TYPE__
218 # elif defined size_t
219 #  define YYSIZE_T size_t
220 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
221      || defined __cplusplus || defined _MSC_VER)
222 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
223 #  define YYSIZE_T size_t
224 # else
225 #  define YYSIZE_T unsigned int
226 # endif
227 #endif
228
229 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
230
231 #ifndef YY_
232 # if YYENABLE_NLS
233 #  if ENABLE_NLS
234 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
235 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
236 #  endif
237 # endif
238 # ifndef YY_
239 #  define YY_(msgid) msgid
240 # endif
241 #endif
242
243 /* Suppress unused-variable warnings by "using" E.  */
244 #if ! defined lint || defined __GNUC__
245 # define YYUSE(e) ((void) (e))
246 #else
247 # define YYUSE(e) /* empty */
248 #endif
249
250 /* Identity function, used to suppress warnings about constant conditions.  */
251 #ifndef lint
252 # define YYID(n) (n)
253 #else
254 #if (defined __STDC__ || defined __C99__FUNC__ \
255      || defined __cplusplus || defined _MSC_VER)
256 static int
257 YYID (int i)
258 #else
259 static int
260 YYID (i)
261     int i;
262 #endif
263 {
264   return i;
265 }
266 #endif
267
268 #if ! defined yyoverflow || YYERROR_VERBOSE
269
270 /* The parser invokes alloca or malloc; define the necessary symbols.  */
271
272 # ifdef YYSTACK_USE_ALLOCA
273 #  if YYSTACK_USE_ALLOCA
274 #   ifdef __GNUC__
275 #    define YYSTACK_ALLOC __builtin_alloca
276 #   elif defined __BUILTIN_VA_ARG_INCR
277 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
278 #   elif defined _AIX
279 #    define YYSTACK_ALLOC __alloca
280 #   elif defined _MSC_VER
281 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
282 #    define alloca _alloca
283 #   else
284 #    define YYSTACK_ALLOC alloca
285 #    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
286      || defined __cplusplus || defined _MSC_VER)
287 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
288 #     ifndef _STDLIB_H
289 #      define _STDLIB_H 1
290 #     endif
291 #    endif
292 #   endif
293 #  endif
294 # endif
295
296 # ifdef YYSTACK_ALLOC
297    /* Pacify GCC's `empty if-body' warning.  */
298 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
299 #  ifndef YYSTACK_ALLOC_MAXIMUM
300     /* The OS might guarantee only one guard page at the bottom of the stack,
301        and a page size can be as small as 4096 bytes.  So we cannot safely
302        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
303        to allow for a few compiler-allocated temporary stack slots.  */
304 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
305 #  endif
306 # else
307 #  define YYSTACK_ALLOC YYMALLOC
308 #  define YYSTACK_FREE YYFREE
309 #  ifndef YYSTACK_ALLOC_MAXIMUM
310 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
311 #  endif
312 #  if (defined __cplusplus && ! defined _STDLIB_H \
313        && ! ((defined YYMALLOC || defined malloc) \
314              && (defined YYFREE || defined free)))
315 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
316 #   ifndef _STDLIB_H
317 #    define _STDLIB_H 1
318 #   endif
319 #  endif
320 #  ifndef YYMALLOC
321 #   define YYMALLOC malloc
322 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
323      || defined __cplusplus || defined _MSC_VER)
324 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
325 #   endif
326 #  endif
327 #  ifndef YYFREE
328 #   define YYFREE free
329 #   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
330      || defined __cplusplus || defined _MSC_VER)
331 void free (void *); /* INFRINGES ON USER NAME SPACE */
332 #   endif
333 #  endif
334 # endif
335 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
336
337
338 #if (! defined yyoverflow \
339      && (! defined __cplusplus \
340          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
341
342 /* A type that is properly aligned for any stack member.  */
343 union yyalloc
344 {
345   yytype_int16 yyss;
346   YYSTYPE yyvs;
347   };
348
349 /* The size of the maximum gap between one aligned stack and the next.  */
350 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
351
352 /* The size of an array large to enough to hold all stacks, each with
353    N elements.  */
354 # define YYSTACK_BYTES(N) \
355      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
356       + YYSTACK_GAP_MAXIMUM)
357
358 /* Copy COUNT objects from FROM to TO.  The source and destination do
359    not overlap.  */
360 # ifndef YYCOPY
361 #  if defined __GNUC__ && 1 < __GNUC__
362 #   define YYCOPY(To, From, Count) \
363       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
364 #  else
365 #   define YYCOPY(To, From, Count)              \
366       do                                        \
367         {                                       \
368           YYSIZE_T yyi;                         \
369           for (yyi = 0; yyi < (Count); yyi++)   \
370             (To)[yyi] = (From)[yyi];            \
371         }                                       \
372       while (YYID (0))
373 #  endif
374 # endif
375
376 /* Relocate STACK from its old location to the new one.  The
377    local variables YYSIZE and YYSTACKSIZE give the old and new number of
378    elements in the stack, and YYPTR gives the new location of the
379    stack.  Advance YYPTR to a properly aligned location for the next
380    stack.  */
381 # define YYSTACK_RELOCATE(Stack)                                        \
382     do                                                                  \
383       {                                                                 \
384         YYSIZE_T yynewbytes;                                            \
385         YYCOPY (&yyptr->Stack, Stack, yysize);                          \
386         Stack = &yyptr->Stack;                                          \
387         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
388         yyptr += yynewbytes / sizeof (*yyptr);                          \
389       }                                                                 \
390     while (YYID (0))
391
392 #endif
393
394 /* YYFINAL -- State number of the termination state.  */
395 #define YYFINAL  3
396 /* YYLAST -- Last index in YYTABLE.  */
397 #define YYLAST   75
398
399 /* YYNTOKENS -- Number of terminals.  */
400 #define YYNTOKENS  17
401 /* YYNNTS -- Number of nonterminals.  */
402 #define YYNNTS  17
403 /* YYNRULES -- Number of rules.  */
404 #define YYNRULES  43
405 /* YYNRULES -- Number of states.  */
406 #define YYNSTATES  56
407
408 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
409 #define YYUNDEFTOK  2
410 #define YYMAXUTOK   265
411
412 #define YYTRANSLATE(YYX)                                                \
413   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
414
415 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
416 static const yytype_uint8 yytranslate[] =
417 {
418        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
419        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
420        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
421        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
422       11,    12,     2,     2,     2,     2,     2,    15,     2,     2,
423        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
424       16,    14,    13,     2,     2,     2,     2,     2,     2,     2,
425        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
426        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
427        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
428        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
429        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
430        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
431        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
432        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
433        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
434        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
435        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
436        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
437        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
438        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
439        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
440        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
441        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
442        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
443        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
444        5,     6,     7,     8,     9,    10
445 };
446
447 #if YYDEBUG
448 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
449    YYRHS.  */
450 static const yytype_uint8 yyprhs[] =
451 {
452        0,     0,     3,     4,     7,     9,    12,    14,    15,    21,
453       22,    27,    29,    30,    36,    37,    44,    45,    50,    52,
454       54,    56,    58,    62,    68,    69,    71,    73,    75,    77,
455       79,    81,    83,    85,    87,    89,    91,    93,    95,    97,
456       99,   101,   103,   105
457 };
458
459 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
460 static const yytype_int8 yyrhs[] =
461 {
462       18,     0,    -1,    -1,    19,    20,    -1,    21,    -1,    21,
463        1,    -1,    23,    -1,    -1,    21,    28,    29,    22,    23,
464       -1,    -1,    11,    24,    21,    12,    -1,    33,    -1,    -1,
465       32,    31,    29,    25,    23,    -1,    -1,    13,    33,    14,
466       33,    26,    21,    -1,    -1,    13,    33,    27,    21,    -1,
467        4,    -1,     5,    -1,     6,    -1,     7,    -1,    29,    15,
468       33,    -1,    29,    15,    33,    30,    33,    -1,    -1,    14,
469       -1,    13,    -1,    16,    -1,     8,    -1,     9,    -1,    10,
470       -1,    14,    -1,    13,    -1,    16,    -1,     8,    -1,     9,
471       -1,    10,    -1,     3,    -1,    33,    -1,     3,    -1,     4,
472       -1,     5,    -1,     6,    -1,     7,    -1
473 };
474
475 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
476 static const yytype_uint8 yyrline[] =
477 {
478        0,    66,    66,    66,    76,    77,    84,    86,    86,   101,
479      101,   108,   114,   114,   121,   121,   127,   127,   138,   138,
480      138,   138,   140,   149,   158,   164,   165,   166,   167,   168,
481      169,   173,   174,   175,   176,   177,   178,   179,   183,   186,
482      187,   188,   189,   190
483 };
484 #endif
485
486 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
487 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
488    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
489 static const char *const yytname[] =
490 {
491   "$end", "error", "$undefined", "TERM", "AND", "OR", "NOT", "PROX", "GE",
492   "LE", "NE", "'('", "')'", "'>'", "'='", "'/'", "'<'", "$accept", "top",
493   "@1", "cqlQuery1", "cqlQuery", "@2", "searchClause", "@3", "@4", "@5",
494   "@6", "boolean", "modifiers", "mrelation", "relation", "index",
495   "searchTerm", 0
496 };
497 #endif
498
499 # ifdef YYPRINT
500 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
501    token YYLEX-NUM.  */
502 static const yytype_uint16 yytoknum[] =
503 {
504        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
505      265,    40,    41,    62,    61,    47,    60
506 };
507 # endif
508
509 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
510 static const yytype_uint8 yyr1[] =
511 {
512        0,    17,    19,    18,    20,    20,    21,    22,    21,    24,
513       23,    23,    25,    23,    26,    23,    27,    23,    28,    28,
514       28,    28,    29,    29,    29,    30,    30,    30,    30,    30,
515       30,    31,    31,    31,    31,    31,    31,    31,    32,    33,
516       33,    33,    33,    33
517 };
518
519 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
520 static const yytype_uint8 yyr2[] =
521 {
522        0,     2,     0,     2,     1,     2,     1,     0,     5,     0,
523        4,     1,     0,     5,     0,     6,     0,     4,     1,     1,
524        1,     1,     3,     5,     0,     1,     1,     1,     1,     1,
525        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
526        1,     1,     1,     1
527 };
528
529 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
530    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
531    means the default is an error.  */
532 static const yytype_uint8 yydefact[] =
533 {
534        2,     0,     0,     1,    39,    40,    41,    42,    43,     9,
535        0,     3,     0,     6,     0,    11,     0,    16,     5,    18,
536       19,    20,    21,    24,    37,    34,    35,    36,    32,    31,
537       33,    24,     0,     0,     0,     7,    12,    10,    14,    17,
538        0,     0,     0,     0,    22,     8,    13,    15,    28,    29,
539       30,    26,    25,    27,     0,    23
540 };
541
542 /* YYDEFGOTO[NTERM-NUM].  */
543 static const yytype_int8 yydefgoto[] =
544 {
545       -1,     1,     2,    11,    12,    41,    13,    16,    42,    43,
546       34,    23,    35,    54,    31,    14,    15
547 };
548
549 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
550    STATE-NUM.  */
551 #define YYPACT_NINF -39
552 static const yytype_int8 yypact[] =
553 {
554      -39,     5,    28,   -39,   -39,   -39,   -39,   -39,   -39,   -39,
555       64,   -39,    59,   -39,    -1,     8,    28,    -8,   -39,   -39,
556      -39,   -39,   -39,   -39,   -39,   -39,   -39,   -39,   -39,   -39,
557      -39,   -39,    50,    64,    28,    -5,    -5,   -39,   -39,    68,
558       64,    28,    28,    28,    37,   -39,   -39,    68,   -39,   -39,
559      -39,   -39,   -39,   -39,    64,   -39
560 };
561
562 /* YYPGOTO[NTERM-NUM].  */
563 static const yytype_int8 yypgoto[] =
564 {
565      -39,   -39,   -39,   -39,   -15,   -39,   -38,   -39,   -39,   -39,
566      -39,   -39,   -17,   -39,   -39,   -39,   -10
567 };
568
569 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
570    positive, shift that token.  If negative, reduce the rule which
571    number is the opposite.  If zero, do what YYDEFACT says.
572    If YYTABLE_NINF, syntax error.  */
573 #define YYTABLE_NINF -39
574 static const yytype_int8 yytable[] =
575 {
576       17,    32,    24,    45,    46,     3,    33,    25,    26,    27,
577       40,   -38,    28,    29,    36,    30,   -38,   -38,   -38,    39,
578        0,   -38,   -38,    38,   -38,     0,     0,     0,    47,     0,
579       44,     4,     5,     6,     7,     8,     0,     0,     0,     9,
580        0,    10,     0,     0,    55,    48,    49,    50,     0,     0,
581       51,    52,     0,    53,    19,    20,    21,    22,     0,    -4,
582       18,     0,    37,    19,    20,    21,    22,     4,     5,     6,
583        7,     8,    19,    20,    21,    22
584 };
585
586 static const yytype_int8 yycheck[] =
587 {
588       10,    16,     3,    41,    42,     0,    14,     8,     9,    10,
589       15,     3,    13,    14,    31,    16,     8,     9,    10,    34,
590       -1,    13,    14,    33,    16,    -1,    -1,    -1,    43,    -1,
591       40,     3,     4,     5,     6,     7,    -1,    -1,    -1,    11,
592       -1,    13,    -1,    -1,    54,     8,     9,    10,    -1,    -1,
593       13,    14,    -1,    16,     4,     5,     6,     7,    -1,     0,
594        1,    -1,    12,     4,     5,     6,     7,     3,     4,     5,
595        6,     7,     4,     5,     6,     7
596 };
597
598 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
599    symbol of state STATE-NUM.  */
600 static const yytype_uint8 yystos[] =
601 {
602        0,    18,    19,     0,     3,     4,     5,     6,     7,    11,
603       13,    20,    21,    23,    32,    33,    24,    33,     1,     4,
604        5,     6,     7,    28,     3,     8,     9,    10,    13,    14,
605       16,    31,    21,    14,    27,    29,    29,    12,    33,    21,
606       15,    22,    25,    26,    33,    23,    23,    21,     8,     9,
607       10,    13,    14,    16,    30,    33
608 };
609
610 #define yyerrok         (yyerrstatus = 0)
611 #define yyclearin       (yychar = YYEMPTY)
612 #define YYEMPTY         (-2)
613 #define YYEOF           0
614
615 #define YYACCEPT        goto yyacceptlab
616 #define YYABORT         goto yyabortlab
617 #define YYERROR         goto yyerrorlab
618
619
620 /* Like YYERROR except do call yyerror.  This remains here temporarily
621    to ease the transition to the new meaning of YYERROR, for GCC.
622    Once GCC version 2 has supplanted version 1, this can go.  */
623
624 #define YYFAIL          goto yyerrlab
625
626 #define YYRECOVERING()  (!!yyerrstatus)
627
628 #define YYBACKUP(Token, Value)                                  \
629 do                                                              \
630   if (yychar == YYEMPTY && yylen == 1)                          \
631     {                                                           \
632       yychar = (Token);                                         \
633       yylval = (Value);                                         \
634       yytoken = YYTRANSLATE (yychar);                           \
635       YYPOPSTACK (1);                                           \
636       goto yybackup;                                            \
637     }                                                           \
638   else                                                          \
639     {                                                           \
640       yyerror (YY_("syntax error: cannot back up")); \
641       YYERROR;                                                  \
642     }                                                           \
643 while (YYID (0))
644
645
646 #define YYTERROR        1
647 #define YYERRCODE       256
648
649
650 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
651    If N is 0, then set CURRENT to the empty location which ends
652    the previous symbol: RHS[0] (always defined).  */
653
654 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
655 #ifndef YYLLOC_DEFAULT
656 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
657     do                                                                  \
658       if (YYID (N))                                                    \
659         {                                                               \
660           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
661           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
662           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
663           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
664         }                                                               \
665       else                                                              \
666         {                                                               \
667           (Current).first_line   = (Current).last_line   =              \
668             YYRHSLOC (Rhs, 0).last_line;                                \
669           (Current).first_column = (Current).last_column =              \
670             YYRHSLOC (Rhs, 0).last_column;                              \
671         }                                                               \
672     while (YYID (0))
673 #endif
674
675
676 /* YY_LOCATION_PRINT -- Print the location on the stream.
677    This macro was not mandated originally: define only if we know
678    we won't break user code: when these are the locations we know.  */
679
680 #ifndef YY_LOCATION_PRINT
681 # if YYLTYPE_IS_TRIVIAL
682 #  define YY_LOCATION_PRINT(File, Loc)                  \
683      fprintf (File, "%d.%d-%d.%d",                      \
684               (Loc).first_line, (Loc).first_column,     \
685               (Loc).last_line,  (Loc).last_column)
686 # else
687 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
688 # endif
689 #endif
690
691
692 /* YYLEX -- calling `yylex' with the right arguments.  */
693
694 #ifdef YYLEX_PARAM
695 # define YYLEX yylex (&yylval, YYLEX_PARAM)
696 #else
697 # define YYLEX yylex (&yylval)
698 #endif
699
700 /* Enable debugging if requested.  */
701 #if YYDEBUG
702
703 # ifndef YYFPRINTF
704 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
705 #  define YYFPRINTF fprintf
706 # endif
707
708 # define YYDPRINTF(Args)                        \
709 do {                                            \
710   if (yydebug)                                  \
711     YYFPRINTF Args;                             \
712 } while (YYID (0))
713
714 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
715 do {                                                                      \
716   if (yydebug)                                                            \
717     {                                                                     \
718       YYFPRINTF (stderr, "%s ", Title);                                   \
719       yy_symbol_print (stderr,                                            \
720                   Type, Value); \
721       YYFPRINTF (stderr, "\n");                                           \
722     }                                                                     \
723 } while (YYID (0))
724
725
726 /*--------------------------------.
727 | Print this symbol on YYOUTPUT.  |
728 `--------------------------------*/
729
730 /*ARGSUSED*/
731 #if (defined __STDC__ || defined __C99__FUNC__ \
732      || defined __cplusplus || defined _MSC_VER)
733 static void
734 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
735 #else
736 static void
737 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
738     FILE *yyoutput;
739     int yytype;
740     YYSTYPE const * const yyvaluep;
741 #endif
742 {
743   if (!yyvaluep)
744     return;
745 # ifdef YYPRINT
746   if (yytype < YYNTOKENS)
747     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
748 # else
749   YYUSE (yyoutput);
750 # endif
751   switch (yytype)
752     {
753       default:
754         break;
755     }
756 }
757
758
759 /*--------------------------------.
760 | Print this symbol on YYOUTPUT.  |
761 `--------------------------------*/
762
763 #if (defined __STDC__ || defined __C99__FUNC__ \
764      || defined __cplusplus || defined _MSC_VER)
765 static void
766 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
767 #else
768 static void
769 yy_symbol_print (yyoutput, yytype, yyvaluep)
770     FILE *yyoutput;
771     int yytype;
772     YYSTYPE const * const yyvaluep;
773 #endif
774 {
775   if (yytype < YYNTOKENS)
776     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
777   else
778     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
779
780   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
781   YYFPRINTF (yyoutput, ")");
782 }
783
784 /*------------------------------------------------------------------.
785 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
786 | TOP (included).                                                   |
787 `------------------------------------------------------------------*/
788
789 #if (defined __STDC__ || defined __C99__FUNC__ \
790      || defined __cplusplus || defined _MSC_VER)
791 static void
792 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
793 #else
794 static void
795 yy_stack_print (bottom, top)
796     yytype_int16 *bottom;
797     yytype_int16 *top;
798 #endif
799 {
800   YYFPRINTF (stderr, "Stack now");
801   for (; bottom <= top; ++bottom)
802     YYFPRINTF (stderr, " %d", *bottom);
803   YYFPRINTF (stderr, "\n");
804 }
805
806 # define YY_STACK_PRINT(Bottom, Top)                            \
807 do {                                                            \
808   if (yydebug)                                                  \
809     yy_stack_print ((Bottom), (Top));                           \
810 } while (YYID (0))
811
812
813 /*------------------------------------------------.
814 | Report that the YYRULE is going to be reduced.  |
815 `------------------------------------------------*/
816
817 #if (defined __STDC__ || defined __C99__FUNC__ \
818      || defined __cplusplus || defined _MSC_VER)
819 static void
820 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
821 #else
822 static void
823 yy_reduce_print (yyvsp, yyrule)
824     YYSTYPE *yyvsp;
825     int yyrule;
826 #endif
827 {
828   int yynrhs = yyr2[yyrule];
829   int yyi;
830   unsigned long int yylno = yyrline[yyrule];
831   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
832              yyrule - 1, yylno);
833   /* The symbols being reduced.  */
834   for (yyi = 0; yyi < yynrhs; yyi++)
835     {
836       fprintf (stderr, "   $%d = ", yyi + 1);
837       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
838                        &(yyvsp[(yyi + 1) - (yynrhs)])
839                                        );
840       fprintf (stderr, "\n");
841     }
842 }
843
844 # define YY_REDUCE_PRINT(Rule)          \
845 do {                                    \
846   if (yydebug)                          \
847     yy_reduce_print (yyvsp, Rule); \
848 } while (YYID (0))
849
850 /* Nonzero means print parse trace.  It is left uninitialized so that
851    multiple parsers can coexist.  */
852 int yydebug;
853 #else /* !YYDEBUG */
854 # define YYDPRINTF(Args)
855 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
856 # define YY_STACK_PRINT(Bottom, Top)
857 # define YY_REDUCE_PRINT(Rule)
858 #endif /* !YYDEBUG */
859
860
861 /* YYINITDEPTH -- initial size of the parser's stacks.  */
862 #ifndef YYINITDEPTH
863 # define YYINITDEPTH 200
864 #endif
865
866 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
867    if the built-in stack extension method is used).
868
869    Do not make this value too large; the results are undefined if
870    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
871    evaluated with infinite-precision integer arithmetic.  */
872
873 #ifndef YYMAXDEPTH
874 # define YYMAXDEPTH 10000
875 #endif
876
877 \f
878
879 #if YYERROR_VERBOSE
880
881 # ifndef yystrlen
882 #  if defined __GLIBC__ && defined _STRING_H
883 #   define yystrlen strlen
884 #  else
885 /* Return the length of YYSTR.  */
886 #if (defined __STDC__ || defined __C99__FUNC__ \
887      || defined __cplusplus || defined _MSC_VER)
888 static YYSIZE_T
889 yystrlen (const char *yystr)
890 #else
891 static YYSIZE_T
892 yystrlen (yystr)
893     const char *yystr;
894 #endif
895 {
896   YYSIZE_T yylen;
897   for (yylen = 0; yystr[yylen]; yylen++)
898     continue;
899   return yylen;
900 }
901 #  endif
902 # endif
903
904 # ifndef yystpcpy
905 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
906 #   define yystpcpy stpcpy
907 #  else
908 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
909    YYDEST.  */
910 #if (defined __STDC__ || defined __C99__FUNC__ \
911      || defined __cplusplus || defined _MSC_VER)
912 static char *
913 yystpcpy (char *yydest, const char *yysrc)
914 #else
915 static char *
916 yystpcpy (yydest, yysrc)
917     char *yydest;
918     const char *yysrc;
919 #endif
920 {
921   char *yyd = yydest;
922   const char *yys = yysrc;
923
924   while ((*yyd++ = *yys++) != '\0')
925     continue;
926
927   return yyd - 1;
928 }
929 #  endif
930 # endif
931
932 # ifndef yytnamerr
933 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
934    quotes and backslashes, so that it's suitable for yyerror.  The
935    heuristic is that double-quoting is unnecessary unless the string
936    contains an apostrophe, a comma, or backslash (other than
937    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
938    null, do not copy; instead, return the length of what the result
939    would have been.  */
940 static YYSIZE_T
941 yytnamerr (char *yyres, const char *yystr)
942 {
943   if (*yystr == '"')
944     {
945       YYSIZE_T yyn = 0;
946       char const *yyp = yystr;
947
948       for (;;)
949         switch (*++yyp)
950           {
951           case '\'':
952           case ',':
953             goto do_not_strip_quotes;
954
955           case '\\':
956             if (*++yyp != '\\')
957               goto do_not_strip_quotes;
958             /* Fall through.  */
959           default:
960             if (yyres)
961               yyres[yyn] = *yyp;
962             yyn++;
963             break;
964
965           case '"':
966             if (yyres)
967               yyres[yyn] = '\0';
968             return yyn;
969           }
970     do_not_strip_quotes: ;
971     }
972
973   if (! yyres)
974     return yystrlen (yystr);
975
976   return yystpcpy (yyres, yystr) - yyres;
977 }
978 # endif
979
980 /* Copy into YYRESULT an error message about the unexpected token
981    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
982    including the terminating null byte.  If YYRESULT is null, do not
983    copy anything; just return the number of bytes that would be
984    copied.  As a special case, return 0 if an ordinary "syntax error"
985    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
986    size calculation.  */
987 static YYSIZE_T
988 yysyntax_error (char *yyresult, int yystate, int yychar)
989 {
990   int yyn = yypact[yystate];
991
992   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
993     return 0;
994   else
995     {
996       int yytype = YYTRANSLATE (yychar);
997       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
998       YYSIZE_T yysize = yysize0;
999       YYSIZE_T yysize1;
1000       int yysize_overflow = 0;
1001       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1002       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1003       int yyx;
1004
1005 # if 0
1006       /* This is so xgettext sees the translatable formats that are
1007          constructed on the fly.  */
1008       YY_("syntax error, unexpected %s");
1009       YY_("syntax error, unexpected %s, expecting %s");
1010       YY_("syntax error, unexpected %s, expecting %s or %s");
1011       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1012       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1013 # endif
1014       char *yyfmt;
1015       char const *yyf;
1016       static char const yyunexpected[] = "syntax error, unexpected %s";
1017       static char const yyexpecting[] = ", expecting %s";
1018       static char const yyor[] = " or %s";
1019       char yyformat[sizeof yyunexpected
1020                     + sizeof yyexpecting - 1
1021                     + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1022                        * (sizeof yyor - 1))];
1023       char const *yyprefix = yyexpecting;
1024
1025       /* Start YYX at -YYN if negative to avoid negative indexes in
1026          YYCHECK.  */
1027       int yyxbegin = yyn < 0 ? -yyn : 0;
1028
1029       /* Stay within bounds of both yycheck and yytname.  */
1030       int yychecklim = YYLAST - yyn + 1;
1031       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1032       int yycount = 1;
1033
1034       yyarg[0] = yytname[yytype];
1035       yyfmt = yystpcpy (yyformat, yyunexpected);
1036
1037       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1038         if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1039           {
1040             if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1041               {
1042                 yycount = 1;
1043                 yysize = yysize0;
1044                 yyformat[sizeof yyunexpected - 1] = '\0';
1045                 break;
1046               }
1047             yyarg[yycount++] = yytname[yyx];
1048             yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1049             yysize_overflow |= (yysize1 < yysize);
1050             yysize = yysize1;
1051             yyfmt = yystpcpy (yyfmt, yyprefix);
1052             yyprefix = yyor;
1053           }
1054
1055       yyf = YY_(yyformat);
1056       yysize1 = yysize + yystrlen (yyf);
1057       yysize_overflow |= (yysize1 < yysize);
1058       yysize = yysize1;
1059
1060       if (yysize_overflow)
1061         return YYSIZE_MAXIMUM;
1062
1063       if (yyresult)
1064         {
1065           /* Avoid sprintf, as that infringes on the user's name space.
1066              Don't have undefined behavior even if the translation
1067              produced a string with the wrong number of "%s"s.  */
1068           char *yyp = yyresult;
1069           int yyi = 0;
1070           while ((*yyp = *yyf) != '\0')
1071             {
1072               if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1073                 {
1074                   yyp += yytnamerr (yyp, yyarg[yyi++]);
1075                   yyf += 2;
1076                 }
1077               else
1078                 {
1079                   yyp++;
1080                   yyf++;
1081                 }
1082             }
1083         }
1084       return yysize;
1085     }
1086 }
1087 #endif /* YYERROR_VERBOSE */
1088 \f
1089
1090 /*-----------------------------------------------.
1091 | Release the memory associated to this symbol.  |
1092 `-----------------------------------------------*/
1093
1094 /*ARGSUSED*/
1095 #if (defined __STDC__ || defined __C99__FUNC__ \
1096      || defined __cplusplus || defined _MSC_VER)
1097 static void
1098 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1099 #else
1100 static void
1101 yydestruct (yymsg, yytype, yyvaluep)
1102     const char *yymsg;
1103     int yytype;
1104     YYSTYPE *yyvaluep;
1105 #endif
1106 {
1107   YYUSE (yyvaluep);
1108
1109   if (!yymsg)
1110     yymsg = "Deleting";
1111   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1112
1113   switch (yytype)
1114     {
1115
1116       default:
1117         break;
1118     }
1119 }
1120 \f
1121
1122 /* Prevent warnings from -Wmissing-prototypes.  */
1123
1124 #ifdef YYPARSE_PARAM
1125 #if defined __STDC__ || defined __cplusplus
1126 int yyparse (void *YYPARSE_PARAM);
1127 #else
1128 int yyparse ();
1129 #endif
1130 #else /* ! YYPARSE_PARAM */
1131 #if defined __STDC__ || defined __cplusplus
1132 int yyparse (void);
1133 #else
1134 int yyparse ();
1135 #endif
1136 #endif /* ! YYPARSE_PARAM */
1137
1138
1139
1140
1141
1142
1143 /*----------.
1144 | yyparse.  |
1145 `----------*/
1146
1147 #ifdef YYPARSE_PARAM
1148 #if (defined __STDC__ || defined __C99__FUNC__ \
1149      || defined __cplusplus || defined _MSC_VER)
1150 int
1151 yyparse (void *YYPARSE_PARAM)
1152 #else
1153 int
1154 yyparse (YYPARSE_PARAM)
1155     void *YYPARSE_PARAM;
1156 #endif
1157 #else /* ! YYPARSE_PARAM */
1158 #if (defined __STDC__ || defined __C99__FUNC__ \
1159      || defined __cplusplus || defined _MSC_VER)
1160 int
1161 yyparse (void)
1162 #else
1163 int
1164 yyparse ()
1165
1166 #endif
1167 #endif
1168 {
1169   /* The look-ahead symbol.  */
1170 int yychar;
1171
1172 /* The semantic value of the look-ahead symbol.  */
1173 YYSTYPE yylval;
1174
1175 /* Number of syntax errors so far.  */
1176 int yynerrs;
1177
1178   int yystate;
1179   int yyn;
1180   int yyresult;
1181   /* Number of tokens to shift before error messages enabled.  */
1182   int yyerrstatus;
1183   /* Look-ahead token as an internal (translated) token number.  */
1184   int yytoken = 0;
1185 #if YYERROR_VERBOSE
1186   /* Buffer for error messages, and its allocated size.  */
1187   char yymsgbuf[128];
1188   char *yymsg = yymsgbuf;
1189   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1190 #endif
1191
1192   /* Three stacks and their tools:
1193      `yyss': related to states,
1194      `yyvs': related to semantic values,
1195      `yyls': related to locations.
1196
1197      Refer to the stacks thru separate pointers, to allow yyoverflow
1198      to reallocate them elsewhere.  */
1199
1200   /* The state stack.  */
1201   yytype_int16 yyssa[YYINITDEPTH];
1202   yytype_int16 *yyss = yyssa;
1203   yytype_int16 *yyssp;
1204
1205   /* The semantic value stack.  */
1206   YYSTYPE yyvsa[YYINITDEPTH];
1207   YYSTYPE *yyvs = yyvsa;
1208   YYSTYPE *yyvsp;
1209
1210
1211
1212 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1213
1214   YYSIZE_T yystacksize = YYINITDEPTH;
1215
1216   /* The variables used to return semantic value and location from the
1217      action routines.  */
1218   YYSTYPE yyval;
1219
1220
1221   /* The number of symbols on the RHS of the reduced rule.
1222      Keep to zero when no symbol should be popped.  */
1223   int yylen = 0;
1224
1225   YYDPRINTF ((stderr, "Starting parse\n"));
1226
1227   yystate = 0;
1228   yyerrstatus = 0;
1229   yynerrs = 0;
1230   yychar = YYEMPTY;             /* Cause a token to be read.  */
1231
1232   /* Initialize stack pointers.
1233      Waste one element of value and location stack
1234      so that they stay on the same level as the state stack.
1235      The wasted elements are never initialized.  */
1236
1237   yyssp = yyss;
1238   yyvsp = yyvs;
1239
1240   goto yysetstate;
1241
1242 /*------------------------------------------------------------.
1243 | yynewstate -- Push a new state, which is found in yystate.  |
1244 `------------------------------------------------------------*/
1245  yynewstate:
1246   /* In all cases, when you get here, the value and location stacks
1247      have just been pushed.  So pushing a state here evens the stacks.  */
1248   yyssp++;
1249
1250  yysetstate:
1251   *yyssp = yystate;
1252
1253   if (yyss + yystacksize - 1 <= yyssp)
1254     {
1255       /* Get the current used size of the three stacks, in elements.  */
1256       YYSIZE_T yysize = yyssp - yyss + 1;
1257
1258 #ifdef yyoverflow
1259       {
1260         /* Give user a chance to reallocate the stack.  Use copies of
1261            these so that the &'s don't force the real ones into
1262            memory.  */
1263         YYSTYPE *yyvs1 = yyvs;
1264         yytype_int16 *yyss1 = yyss;
1265
1266
1267         /* Each stack pointer address is followed by the size of the
1268            data in use in that stack, in bytes.  This used to be a
1269            conditional around just the two extra args, but that might
1270            be undefined if yyoverflow is a macro.  */
1271         yyoverflow (YY_("memory exhausted"),
1272                     &yyss1, yysize * sizeof (*yyssp),
1273                     &yyvs1, yysize * sizeof (*yyvsp),
1274
1275                     &yystacksize);
1276
1277         yyss = yyss1;
1278         yyvs = yyvs1;
1279       }
1280 #else /* no yyoverflow */
1281 # ifndef YYSTACK_RELOCATE
1282       goto yyexhaustedlab;
1283 # else
1284       /* Extend the stack our own way.  */
1285       if (YYMAXDEPTH <= yystacksize)
1286         goto yyexhaustedlab;
1287       yystacksize *= 2;
1288       if (YYMAXDEPTH < yystacksize)
1289         yystacksize = YYMAXDEPTH;
1290
1291       {
1292         yytype_int16 *yyss1 = yyss;
1293         union yyalloc *yyptr =
1294           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1295         if (! yyptr)
1296           goto yyexhaustedlab;
1297         YYSTACK_RELOCATE (yyss);
1298         YYSTACK_RELOCATE (yyvs);
1299
1300 #  undef YYSTACK_RELOCATE
1301         if (yyss1 != yyssa)
1302           YYSTACK_FREE (yyss1);
1303       }
1304 # endif
1305 #endif /* no yyoverflow */
1306
1307       yyssp = yyss + yysize - 1;
1308       yyvsp = yyvs + yysize - 1;
1309
1310
1311       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1312                   (unsigned long int) yystacksize));
1313
1314       if (yyss + yystacksize - 1 <= yyssp)
1315         YYABORT;
1316     }
1317
1318   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1319
1320   goto yybackup;
1321
1322 /*-----------.
1323 | yybackup.  |
1324 `-----------*/
1325 yybackup:
1326
1327   /* Do appropriate processing given the current state.  Read a
1328      look-ahead token if we need one and don't already have one.  */
1329
1330   /* First try to decide what to do without reference to look-ahead token.  */
1331   yyn = yypact[yystate];
1332   if (yyn == YYPACT_NINF)
1333     goto yydefault;
1334
1335   /* Not known => get a look-ahead token if don't already have one.  */
1336
1337   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
1338   if (yychar == YYEMPTY)
1339     {
1340       YYDPRINTF ((stderr, "Reading a token: "));
1341       yychar = YYLEX;
1342     }
1343
1344   if (yychar <= YYEOF)
1345     {
1346       yychar = yytoken = YYEOF;
1347       YYDPRINTF ((stderr, "Now at end of input.\n"));
1348     }
1349   else
1350     {
1351       yytoken = YYTRANSLATE (yychar);
1352       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1353     }
1354
1355   /* If the proper action on seeing token YYTOKEN is to reduce or to
1356      detect an error, take that action.  */
1357   yyn += yytoken;
1358   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1359     goto yydefault;
1360   yyn = yytable[yyn];
1361   if (yyn <= 0)
1362     {
1363       if (yyn == 0 || yyn == YYTABLE_NINF)
1364         goto yyerrlab;
1365       yyn = -yyn;
1366       goto yyreduce;
1367     }
1368
1369   if (yyn == YYFINAL)
1370     YYACCEPT;
1371
1372   /* Count tokens shifted since error; after three, turn off error
1373      status.  */
1374   if (yyerrstatus)
1375     yyerrstatus--;
1376
1377   /* Shift the look-ahead token.  */
1378   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1379
1380   /* Discard the shifted token unless it is eof.  */
1381   if (yychar != YYEOF)
1382     yychar = YYEMPTY;
1383
1384   yystate = yyn;
1385   *++yyvsp = yylval;
1386
1387   goto yynewstate;
1388
1389
1390 /*-----------------------------------------------------------.
1391 | yydefault -- do the default action for the current state.  |
1392 `-----------------------------------------------------------*/
1393 yydefault:
1394   yyn = yydefact[yystate];
1395   if (yyn == 0)
1396     goto yyerrlab;
1397   goto yyreduce;
1398
1399
1400 /*-----------------------------.
1401 | yyreduce -- Do a reduction.  |
1402 `-----------------------------*/
1403 yyreduce:
1404   /* yyn is the number of a rule to reduce with.  */
1405   yylen = yyr2[yyn];
1406
1407   /* If YYLEN is nonzero, implement the default value of the action:
1408      `$$ = $1'.
1409
1410      Otherwise, the following line sets YYVAL to garbage.
1411      This behavior is undocumented and Bison
1412      users should not rely upon it.  Assigning to YYVAL
1413      unconditionally makes the parser a bit smaller, and it avoids a
1414      GCC warning that YYVAL may be used uninitialized.  */
1415   yyval = yyvsp[1-yylen];
1416
1417
1418   YY_REDUCE_PRINT (yyn);
1419   switch (yyn)
1420     {
1421         case 2:
1422 #line 66 "cql.y"
1423     { 
1424     (yyval).rel = cql_node_mk_sc(((CQL_parser) parm)->nmem,
1425                             "cql.serverChoice", "scr", 0);
1426     ((CQL_parser) parm)->top = 0;
1427 }
1428     break;
1429
1430   case 3:
1431 #line 70 "cql.y"
1432     {
1433     cql_node_destroy((yyval).rel);
1434     ((CQL_parser) parm)->top = (yyvsp[(2) - (2)]).cql; 
1435 }
1436     break;
1437
1438   case 5:
1439 #line 77 "cql.y"
1440     {
1441     cql_node_destroy((yyvsp[(1) - (2)]).cql);
1442     (yyval).cql = 0;
1443 }
1444     break;
1445
1446   case 7:
1447 #line 86 "cql.y"
1448     { 
1449       (yyval).rel = (yyvsp[(0) - (3)]).rel;
1450   }
1451     break;
1452
1453   case 8:
1454 #line 88 "cql.y"
1455     {
1456       struct cql_node *cn = cql_node_mk_boolean(((CQL_parser) parm)->nmem,
1457                                                 (yyvsp[(2) - (5)]).buf);
1458       
1459       cn->u.boolean.modifiers = (yyvsp[(3) - (5)]).cql;
1460       cn->u.boolean.left = (yyvsp[(1) - (5)]).cql;
1461       cn->u.boolean.right = (yyvsp[(5) - (5)]).cql;
1462
1463       (yyval).cql = cn;
1464   }
1465     break;
1466
1467   case 9:
1468 #line 101 "cql.y"
1469     { 
1470       (yyval).rel = (yyvsp[(0) - (1)]).rel;
1471       
1472   }
1473     break;
1474
1475   case 10:
1476 #line 104 "cql.y"
1477     {
1478       (yyval).cql = (yyvsp[(3) - (4)]).cql;
1479   }
1480     break;
1481
1482   case 11:
1483 #line 108 "cql.y"
1484     {
1485       struct cql_node *st = cql_node_dup (((CQL_parser) parm)->nmem, (yyvsp[(0) - (1)]).rel);
1486       st->u.st.term = nmem_strdup(((CQL_parser)parm)->nmem, (yyvsp[(1) - (1)]).buf);
1487       (yyval).cql = st;
1488   }
1489     break;
1490
1491   case 12:
1492 #line 114 "cql.y"
1493     {
1494       (yyval).rel = cql_node_mk_sc(((CQL_parser) parm)->nmem, (yyvsp[(1) - (3)]).buf, (yyvsp[(2) - (3)]).buf, 0);
1495       (yyval).rel->u.st.modifiers = (yyvsp[(3) - (3)]).cql;
1496   }
1497     break;
1498
1499   case 13:
1500 #line 117 "cql.y"
1501     {
1502       (yyval).cql = (yyvsp[(5) - (5)]).cql;
1503       cql_node_destroy((yyvsp[(4) - (5)]).rel);
1504   }
1505     break;
1506
1507   case 14:
1508 #line 121 "cql.y"
1509     {
1510       (yyval).rel = (yyvsp[(0) - (4)]).rel;
1511   }
1512     break;
1513
1514   case 15:
1515 #line 123 "cql.y"
1516     {
1517     (yyval).cql = cql_apply_prefix(((CQL_parser) parm)->nmem,
1518                               (yyvsp[(6) - (6)]).cql, (yyvsp[(2) - (6)]).buf, (yyvsp[(4) - (6)]).buf);
1519   }
1520     break;
1521
1522   case 16:
1523 #line 127 "cql.y"
1524     {
1525       (yyval).rel = (yyvsp[(0) - (2)]).rel;
1526   }
1527     break;
1528
1529   case 17:
1530 #line 129 "cql.y"
1531     {
1532     (yyval).cql = cql_apply_prefix(((CQL_parser) parm)->nmem, 
1533                               (yyvsp[(4) - (4)]).cql, 0, (yyvsp[(2) - (4)]).buf);
1534    }
1535     break;
1536
1537   case 22:
1538 #line 141 "cql.y"
1539     { 
1540     struct cql_node *mod = cql_node_mk_sc(((CQL_parser)parm)->nmem,
1541                                           (yyvsp[(3) - (3)]).buf, 0, 0);
1542
1543     mod->u.st.modifiers = (yyvsp[(1) - (3)]).cql;
1544     (yyval).cql = mod;
1545 }
1546     break;
1547
1548   case 23:
1549 #line 150 "cql.y"
1550     {
1551     struct cql_node *mod = cql_node_mk_sc(((CQL_parser)parm)->nmem,
1552                                           (yyvsp[(3) - (5)]).buf, (yyvsp[(4) - (5)]).buf, (yyvsp[(5) - (5)]).buf);
1553
1554     mod->u.st.modifiers = (yyvsp[(1) - (5)]).cql;
1555     (yyval).cql = mod;
1556 }
1557     break;
1558
1559   case 24:
1560 #line 158 "cql.y"
1561     { 
1562     (yyval).cql = 0;
1563 }
1564     break;
1565
1566
1567 /* Line 1267 of yacc.c.  */
1568 #line 1569 "cql.c"
1569       default: break;
1570     }
1571   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1572
1573   YYPOPSTACK (yylen);
1574   yylen = 0;
1575   YY_STACK_PRINT (yyss, yyssp);
1576
1577   *++yyvsp = yyval;
1578
1579
1580   /* Now `shift' the result of the reduction.  Determine what state
1581      that goes to, based on the state we popped back to and the rule
1582      number reduced by.  */
1583
1584   yyn = yyr1[yyn];
1585
1586   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1587   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1588     yystate = yytable[yystate];
1589   else
1590     yystate = yydefgoto[yyn - YYNTOKENS];
1591
1592   goto yynewstate;
1593
1594
1595 /*------------------------------------.
1596 | yyerrlab -- here on detecting error |
1597 `------------------------------------*/
1598 yyerrlab:
1599   /* If not already recovering from an error, report this error.  */
1600   if (!yyerrstatus)
1601     {
1602       ++yynerrs;
1603 #if ! YYERROR_VERBOSE
1604       yyerror (YY_("syntax error"));
1605 #else
1606       {
1607         YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1608         if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1609           {
1610             YYSIZE_T yyalloc = 2 * yysize;
1611             if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1612               yyalloc = YYSTACK_ALLOC_MAXIMUM;
1613             if (yymsg != yymsgbuf)
1614               YYSTACK_FREE (yymsg);
1615             yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1616             if (yymsg)
1617               yymsg_alloc = yyalloc;
1618             else
1619               {
1620                 yymsg = yymsgbuf;
1621                 yymsg_alloc = sizeof yymsgbuf;
1622               }
1623           }
1624
1625         if (0 < yysize && yysize <= yymsg_alloc)
1626           {
1627             (void) yysyntax_error (yymsg, yystate, yychar);
1628             yyerror (yymsg);
1629           }
1630         else
1631           {
1632             yyerror (YY_("syntax error"));
1633             if (yysize != 0)
1634               goto yyexhaustedlab;
1635           }
1636       }
1637 #endif
1638     }
1639
1640
1641
1642   if (yyerrstatus == 3)
1643     {
1644       /* If just tried and failed to reuse look-ahead token after an
1645          error, discard it.  */
1646
1647       if (yychar <= YYEOF)
1648         {
1649           /* Return failure if at end of input.  */
1650           if (yychar == YYEOF)
1651             YYABORT;
1652         }
1653       else
1654         {
1655           yydestruct ("Error: discarding",
1656                       yytoken, &yylval);
1657           yychar = YYEMPTY;
1658         }
1659     }
1660
1661   /* Else will try to reuse look-ahead token after shifting the error
1662      token.  */
1663   goto yyerrlab1;
1664
1665
1666 /*---------------------------------------------------.
1667 | yyerrorlab -- error raised explicitly by YYERROR.  |
1668 `---------------------------------------------------*/
1669 yyerrorlab:
1670
1671   /* Pacify compilers like GCC when the user code never invokes
1672      YYERROR and the label yyerrorlab therefore never appears in user
1673      code.  */
1674   if (/*CONSTCOND*/ 0)
1675      goto yyerrorlab;
1676
1677   /* Do not reclaim the symbols of the rule which action triggered
1678      this YYERROR.  */
1679   YYPOPSTACK (yylen);
1680   yylen = 0;
1681   YY_STACK_PRINT (yyss, yyssp);
1682   yystate = *yyssp;
1683   goto yyerrlab1;
1684
1685
1686 /*-------------------------------------------------------------.
1687 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1688 `-------------------------------------------------------------*/
1689 yyerrlab1:
1690   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1691
1692   for (;;)
1693     {
1694       yyn = yypact[yystate];
1695       if (yyn != YYPACT_NINF)
1696         {
1697           yyn += YYTERROR;
1698           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1699             {
1700               yyn = yytable[yyn];
1701               if (0 < yyn)
1702                 break;
1703             }
1704         }
1705
1706       /* Pop the current state because it cannot handle the error token.  */
1707       if (yyssp == yyss)
1708         YYABORT;
1709
1710
1711       yydestruct ("Error: popping",
1712                   yystos[yystate], yyvsp);
1713       YYPOPSTACK (1);
1714       yystate = *yyssp;
1715       YY_STACK_PRINT (yyss, yyssp);
1716     }
1717
1718   if (yyn == YYFINAL)
1719     YYACCEPT;
1720
1721   *++yyvsp = yylval;
1722
1723
1724   /* Shift the error token.  */
1725   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1726
1727   yystate = yyn;
1728   goto yynewstate;
1729
1730
1731 /*-------------------------------------.
1732 | yyacceptlab -- YYACCEPT comes here.  |
1733 `-------------------------------------*/
1734 yyacceptlab:
1735   yyresult = 0;
1736   goto yyreturn;
1737
1738 /*-----------------------------------.
1739 | yyabortlab -- YYABORT comes here.  |
1740 `-----------------------------------*/
1741 yyabortlab:
1742   yyresult = 1;
1743   goto yyreturn;
1744
1745 #ifndef yyoverflow
1746 /*-------------------------------------------------.
1747 | yyexhaustedlab -- memory exhaustion comes here.  |
1748 `-------------------------------------------------*/
1749 yyexhaustedlab:
1750   yyerror (YY_("memory exhausted"));
1751   yyresult = 2;
1752   /* Fall through.  */
1753 #endif
1754
1755 yyreturn:
1756   if (yychar != YYEOF && yychar != YYEMPTY)
1757      yydestruct ("Cleanup: discarding lookahead",
1758                  yytoken, &yylval);
1759   /* Do not reclaim the symbols of the rule which action triggered
1760      this YYABORT or YYACCEPT.  */
1761   YYPOPSTACK (yylen);
1762   YY_STACK_PRINT (yyss, yyssp);
1763   while (yyssp != yyss)
1764     {
1765       yydestruct ("Cleanup: popping",
1766                   yystos[*yyssp], yyvsp);
1767       YYPOPSTACK (1);
1768     }
1769 #ifndef yyoverflow
1770   if (yyss != yyssa)
1771     YYSTACK_FREE (yyss);
1772 #endif
1773 #if YYERROR_VERBOSE
1774   if (yymsg != yymsgbuf)
1775     YYSTACK_FREE (yymsg);
1776 #endif
1777   /* Make sure YYID is used.  */
1778   return YYID (yyresult);
1779 }
1780
1781
1782 #line 193 "cql.y"
1783
1784
1785 int yyerror(char *s)
1786 {
1787     return 0;
1788 }
1789
1790 /**
1791  * putb is a utility that puts one character to the string
1792  * in current lexical token. This routine deallocates as
1793  * necessary using NMEM.
1794  */
1795
1796 static void putb(YYSTYPE *lval, CQL_parser cp, int c)
1797 {
1798     if (lval->len+1 >= lval->size)
1799     {
1800         char *nb = (char *)
1801             nmem_malloc(cp->nmem, (lval->size = lval->len * 2 + 20));
1802         memcpy (nb, lval->buf, lval->len);
1803         lval->buf = nb;
1804     }
1805     if (c)
1806         lval->buf[lval->len++] = c;
1807     lval->buf[lval->len] = '\0';
1808 }
1809
1810
1811 /**
1812  * yylex returns next token for Bison to be read. In this
1813  * case one of the CQL terminals are returned.
1814  */
1815 int yylex(YYSTYPE *lval, void *vp)
1816 {
1817     CQL_parser cp = (CQL_parser) vp;
1818     int c;
1819     lval->cql = 0;
1820     lval->rel = 0;
1821     lval->len = 0;
1822     lval->size = 10;
1823     lval->buf = (char *) nmem_malloc(cp->nmem, lval->size);
1824     lval->buf[0] = '\0';
1825     do
1826     {
1827         c = cp->getbyte(cp->client_data);
1828         if (c == 0)
1829             return 0;
1830         if (c == '\n')
1831             return 0;
1832     } while (isspace(c));
1833     if (strchr("()=></", c))
1834     {
1835         int c1;
1836         putb(lval, cp, c);
1837         if (c == '>')
1838         {
1839             c1 = cp->getbyte(cp->client_data);
1840             if (c1 == '=')
1841             {
1842                 putb(lval, cp, c1);
1843                 return GE;
1844             }
1845             else
1846                 cp->ungetbyte(c1, cp->client_data);
1847         }
1848         else if (c == '<')
1849         {
1850             c1 = cp->getbyte(cp->client_data);
1851             if (c1 == '=')
1852             {
1853                 putb(lval, cp, c1);
1854                 return LE;
1855             }
1856             else if (c1 == '>')
1857             {
1858                 putb(lval, cp, c1);
1859                 return NE;
1860             }
1861             else
1862                 cp->ungetbyte(c1, cp->client_data);
1863         }
1864         return c;
1865     }
1866     if (c == '"')
1867     {
1868         while ((c = cp->getbyte(cp->client_data)) != 0 && c != '"')
1869         {
1870             if (c == '\\')
1871                 c = cp->getbyte(cp->client_data);
1872             putb(lval, cp, c);
1873         }
1874         putb(lval, cp, 0);
1875     }
1876     else
1877     {
1878         while (c != 0 && !strchr(" \n()=<>/", c))
1879         {
1880             if (c == '\\')
1881                 c = cp->getbyte(cp->client_data);
1882             putb(lval, cp, c);
1883             c = cp->getbyte(cp->client_data);
1884         }
1885 #if YYDEBUG
1886         printf ("got %s\n", lval->buf);
1887 #endif
1888         if (c != 0)
1889             cp->ungetbyte(c, cp->client_data);
1890         if (!cql_strcmp(lval->buf, "and"))
1891         {
1892             lval->buf = "and";
1893             return AND;
1894         }
1895         if (!cql_strcmp(lval->buf, "or"))
1896         {
1897             lval->buf = "or";
1898             return OR;
1899         }
1900         if (!cql_strcmp(lval->buf, "not"))
1901         {
1902             lval->buf = "not";
1903             return NOT;
1904         }
1905         if (!cql_strcmp(lval->buf, "prox"))
1906         {
1907             lval->buf = "prox";
1908             return PROX;
1909         }
1910     }
1911     return TERM;
1912 }
1913
1914
1915 int cql_parser_stream(CQL_parser cp,
1916                       int (*getbyte)(void *client_data),
1917                       void (*ungetbyte)(int b, void *client_data),
1918                       void *client_data)
1919 {
1920     nmem_reset(cp->nmem);
1921     cp->getbyte = getbyte;
1922     cp->ungetbyte = ungetbyte;
1923     cp->client_data = client_data;
1924     if (cp->top)
1925         cql_node_destroy(cp->top);
1926     cql_parse(cp);
1927     if (cp->top)
1928         return 0;
1929     return -1;
1930 }
1931
1932 CQL_parser cql_parser_create(void)
1933 {
1934     CQL_parser cp = (CQL_parser) xmalloc (sizeof(*cp));
1935
1936     cp->top = 0;
1937     cp->getbyte = 0;
1938     cp->ungetbyte = 0;
1939     cp->client_data = 0;
1940     cp->last_error = 0;
1941     cp->last_pos = 0;
1942     cp->nmem = nmem_create();
1943     return cp;
1944 }
1945
1946 void cql_parser_destroy(CQL_parser cp)
1947 {
1948     cql_node_destroy(cp->top);
1949     nmem_destroy(cp->nmem);
1950     xfree (cp);
1951 }
1952
1953 struct cql_node *cql_parser_result(CQL_parser cp)
1954 {
1955     return cp->top;
1956 }
1957