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