source: branches/New_Config_Format-branch/gsdl/packages/mg/src/text/bool_parser.c@ 1279

Last change on this file since 1279 was 1279, checked in by sjboddie, 24 years ago

merged changes to trunk into New_Config_Format branch

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 30.7 KB
Line 
1
2/* A Bison parser, made from bool_parser.y
3 by GNU Bison version 1.27
4 */
5
6#define YYBISON 1 /* Identify Bison output. */
7
8#define TERM 257
9
10#line 24 "bool_parser.y"
11
12
13#include "sysfuncs.h"
14
15#include "messages.h"
16
17#include "memlib.h"
18#include "words.h"
19#include "stemmer.h"
20#include "term_lists.h"
21#include "bool_tree.h"
22/* [RPAP - Jan 97: Stem Index Change] */
23#include "backend.h" /* for stemmed_dict def */
24#include "stem_search.h"
25
26#include "query_term_list.h" /* [RPAP - Feb 97: Term Frequency] */
27
28/* --- routines --- */
29static int query_lex();
30static int yyerror(char *);
31#define yylex() query_lex(&ch_buf, end_buf)
32
33/* --- module variables --- */
34static char *ch_buf; /* ptr to the character query line buffer */
35static char *end_buf; /* ptr to the last character of the line buffer */
36static bool_tree_node *tree_base = NULL;
37static TermList **term_list;
38static int stemmer_num;
39static int stem_method;
40/* [RPAP - Jan 97: Stem Index Change] */
41stemmed_dict *p__sd;
42static int indexed;
43/* [RPAP - Feb 97: Term Frequency] */
44static QueryTermList **query_term_list;
45static int word_num;
46static u_long count;
47static u_long doc_count;
48static u_long invf_ptr;
49static u_long invf_len;
50
51#line 66 "bool_parser.y"
52typedef union {
53 char *text;
54 bool_tree_node *node;
55} YYSTYPE;
56#include <stdio.h>
57
58#ifndef __cplusplus
59#ifndef __STDC__
60#define const
61#endif
62#endif
63
64
65
66#define YYFINAL 20
67#define YYFLAG -32768
68#define YYNTBASE 11
69
70#define YYTRANSLATE(x) ((unsigned)(x) <= 257 ? yytranslate[x] : 16)
71
72static const char yytranslate[] = { 0,
73 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
74 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
75 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
76 2, 2, 8, 2, 2, 2, 2, 9, 2, 4,
77 5, 6, 2, 2, 2, 2, 2, 2, 2, 2,
78 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
79 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
80 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
81 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
82 2, 2, 2, 2, 7, 2, 2, 2, 2, 2,
83 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
84 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
85 2, 2, 2, 10, 2, 2, 2, 2, 2, 2,
86 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
87 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
88 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
89 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
90 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
91 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
92 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
93 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
94 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
95 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
96 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
97 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
98 2, 2, 2, 2, 2, 1, 3
99};
100
101#if YYDEBUG != 0
102static const short yyprhs[] = { 0,
103 0, 2, 4, 8, 10, 12, 14, 17, 21, 24,
104 26, 30
105};
106
107static const short yyrhs[] = { 15,
108 0, 3, 0, 4, 15, 5, 0, 6, 0, 7,
109 0, 12, 0, 8, 13, 0, 14, 9, 13, 0,
110 14, 13, 0, 13, 0, 15, 10, 14, 0, 14,
111 0
112};
113
114#endif
115
116#if YYDEBUG != 0
117static const short yyrline[] = { 0,
118 76, 80, 81, 82, 83, 86, 87, 90, 91, 92,
119 95, 96
120};
121#endif
122
123
124#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
125
126static const char * const yytname[] = { "$","error","$undefined.","TERM","'('",
127"')'","'*'","'_'","'!'","'&'","'|'","query","term","not","and","or", NULL
128};
129#endif
130
131static const short yyr1[] = { 0,
132 11, 12, 12, 12, 12, 13, 13, 14, 14, 14,
133 15, 15
134};
135
136static const short yyr2[] = { 0,
137 1, 1, 3, 1, 1, 1, 2, 3, 2, 1,
138 3, 1
139};
140
141static const short yydefact[] = { 0,
142 2, 0, 4, 5, 0, 6, 10, 12, 1, 0,
143 7, 0, 9, 0, 3, 8, 11, 0, 0, 0
144};
145
146static const short yydefgoto[] = { 18,
147 6, 7, 8, 9
148};
149
150static const short yypact[] = { 10,
151-32768, 10,-32768,-32768, 10,-32768,-32768, 2, -9, 14,
152-32768, 10,-32768, 10,-32768,-32768, 2, 4, 15,-32768
153};
154
155static const short yypgoto[] = {-32768,
156-32768, -5, -12, 18
157};
158
159
160#define YYLAST 24
161
162
163static const short yytable[] = { 11,
164 14, 17, 13, 19, 1, 2, 16, 3, 4, 5,
165 12, 13, 1, 2, 20, 3, 4, 5, 15, 10,
166 0, 0, 0, 14
167};
168
169static const short yycheck[] = { 5,
170 10, 14, 8, 0, 3, 4, 12, 6, 7, 8,
171 9, 17, 3, 4, 0, 6, 7, 8, 5, 2,
172 -1, -1, -1, 10
173};
174/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
175#line 3 "/usr/share/bison.simple"
176/* This file comes from bison-1.27. */
177
178/* Skeleton output parser for bison,
179 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
180
181 This program is free software; you can redistribute it and/or modify
182 it under the terms of the GNU General Public License as published by
183 the Free Software Foundation; either version 2, or (at your option)
184 any later version.
185
186 This program is distributed in the hope that it will be useful,
187 but WITHOUT ANY WARRANTY; without even the implied warranty of
188 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
189 GNU General Public License for more details.
190
191 You should have received a copy of the GNU General Public License
192 along with this program; if not, write to the Free Software
193 Foundation, Inc., 59 Temple Place - Suite 330,
194 Boston, MA 02111-1307, USA. */
195
196/* As a special exception, when this file is copied by Bison into a
197 Bison output file, you may use that output file without restriction.
198 This special exception was added by the Free Software Foundation
199 in version 1.24 of Bison. */
200
201/* This is the parser code that is written into each bison parser
202 when the %semantic_parser declaration is not specified in the grammar.
203 It was written by Richard Stallman by simplifying the hairy parser
204 used when %semantic_parser is specified. */
205
206#ifndef YYSTACK_USE_ALLOCA
207#ifdef alloca
208#define YYSTACK_USE_ALLOCA
209#else /* alloca not defined */
210#ifdef __GNUC__
211#define YYSTACK_USE_ALLOCA
212#define alloca __builtin_alloca
213#else /* not GNU C. */
214#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
215#define YYSTACK_USE_ALLOCA
216#include <alloca.h>
217#else /* not sparc */
218/* We think this test detects Watcom and Microsoft C. */
219/* This used to test MSDOS, but that is a bad idea
220 since that symbol is in the user namespace. */
221#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
222#if 0 /* No need for malloc.h, which pollutes the namespace;
223 instead, just don't use alloca. */
224#include <malloc.h>
225#endif
226#else /* not MSDOS, or __TURBOC__ */
227#if defined(_AIX)
228/* I don't know what this was needed for, but it pollutes the namespace.
229 So I turned it off. rms, 2 May 1997. */
230/* #include <malloc.h> */
231 #pragma alloca
232#define YYSTACK_USE_ALLOCA
233#else /* not MSDOS, or __TURBOC__, or _AIX */
234#if 0
235#ifdef __hpux /* [email protected] says this works for HPUX 9.05 and up,
236 and on HPUX 10. Eventually we can turn this on. */
237#define YYSTACK_USE_ALLOCA
238#define alloca __builtin_alloca
239#endif /* __hpux */
240#endif
241#endif /* not _AIX */
242#endif /* not MSDOS, or __TURBOC__ */
243#endif /* not sparc */
244#endif /* not GNU C */
245#endif /* alloca not defined */
246#endif /* YYSTACK_USE_ALLOCA not defined */
247
248#ifdef YYSTACK_USE_ALLOCA
249#define YYSTACK_ALLOC alloca
250#else
251#define YYSTACK_ALLOC malloc
252#endif
253
254/* Note: there must be only one dollar sign in this file.
255 It is replaced by the list of actions, each action
256 as one case of the switch. */
257
258#define yyerrok (yyerrstatus = 0)
259#define yyclearin (yychar = YYEMPTY)
260#define YYEMPTY -2
261#define YYEOF 0
262#define YYACCEPT goto yyacceptlab
263#define YYABORT goto yyabortlab
264#define YYERROR goto yyerrlab1
265/* Like YYERROR except do call yyerror.
266 This remains here temporarily to ease the
267 transition to the new meaning of YYERROR, for GCC.
268 Once GCC version 2 has supplanted version 1, this can go. */
269#define YYFAIL goto yyerrlab
270#define YYRECOVERING() (!!yyerrstatus)
271#define YYBACKUP(token, value) \
272do \
273 if (yychar == YYEMPTY && yylen == 1) \
274 { yychar = (token), yylval = (value); \
275 yychar1 = YYTRANSLATE (yychar); \
276 YYPOPSTACK; \
277 goto yybackup; \
278 } \
279 else \
280 { yyerror ("syntax error: cannot back up"); YYERROR; } \
281while (0)
282
283#define YYTERROR 1
284#define YYERRCODE 256
285
286#ifndef YYPURE
287#define YYLEX yylex()
288#endif
289
290#ifdef YYPURE
291#ifdef YYLSP_NEEDED
292#ifdef YYLEX_PARAM
293#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
294#else
295#define YYLEX yylex(&yylval, &yylloc)
296#endif
297#else /* not YYLSP_NEEDED */
298#ifdef YYLEX_PARAM
299#define YYLEX yylex(&yylval, YYLEX_PARAM)
300#else
301#define YYLEX yylex(&yylval)
302#endif
303#endif /* not YYLSP_NEEDED */
304#endif
305
306/* If nonreentrant, generate the variables here */
307
308#ifndef YYPURE
309
310int yychar; /* the lookahead symbol */
311YYSTYPE yylval; /* the semantic value of the */
312 /* lookahead symbol */
313
314#ifdef YYLSP_NEEDED
315YYLTYPE yylloc; /* location data for the lookahead */
316 /* symbol */
317#endif
318
319int yynerrs; /* number of parse errors so far */
320#endif /* not YYPURE */
321
322#if YYDEBUG != 0
323int yydebug; /* nonzero means print parse trace */
324/* Since this is uninitialized, it does not stop multiple parsers
325 from coexisting. */
326#endif
327
328/* YYINITDEPTH indicates the initial size of the parser's stacks */
329
330#ifndef YYINITDEPTH
331#define YYINITDEPTH 200
332#endif
333
334/* YYMAXDEPTH is the maximum size the stacks can grow to
335 (effective only if the built-in stack extension method is used). */
336
337#if YYMAXDEPTH == 0
338#undef YYMAXDEPTH
339#endif
340
341#ifndef YYMAXDEPTH
342#define YYMAXDEPTH 10000
343#endif
344
345
346/* Define __yy_memcpy. Note that the size argument
347 should be passed with type unsigned int, because that is what the non-GCC
348 definitions require. With GCC, __builtin_memcpy takes an arg
349 of type size_t, but it can handle unsigned int. */
350
351#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
352#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
353#else /* not GNU C or C++ */
354#ifndef __cplusplus
355
356/* This is the most reliable way to avoid incompatibilities
357 in available built-in functions on various systems. */
358static void
359__yy_memcpy (to, from, count)
360 char *to;
361 char *from;
362 unsigned int count;
363{
364 register char *f = from;
365 register char *t = to;
366 register int i = count;
367
368 while (i-- > 0)
369 *t++ = *f++;
370}
371
372#else /* __cplusplus */
373
374/* This is the most reliable way to avoid incompatibilities
375 in available built-in functions on various systems. */
376static void
377__yy_memcpy (char *to, char *from, unsigned int count)
378{
379 register char *t = to;
380 register char *f = from;
381 register int i = count;
382
383 while (i-- > 0)
384 *t++ = *f++;
385}
386
387#endif
388#endif
389
390
391#line 216 "/usr/share/bison.simple"
392
393/* The user can define YYPARSE_PARAM as the name of an argument to be passed
394 into yyparse. The argument should have type void *.
395 It should actually point to an object.
396 Grammar actions can access the variable by casting it
397 to the proper pointer type. */
398
399#ifdef YYPARSE_PARAM
400#ifdef __cplusplus
401#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
402#define YYPARSE_PARAM_DECL
403#else /* not __cplusplus */
404#define YYPARSE_PARAM_ARG YYPARSE_PARAM
405#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
406#endif /* not __cplusplus */
407#else /* not YYPARSE_PARAM */
408#define YYPARSE_PARAM_ARG
409#define YYPARSE_PARAM_DECL
410#endif /* not YYPARSE_PARAM */
411
412/* Prevent warning if -Wstrict-prototypes. */
413#ifdef __GNUC__
414#ifdef YYPARSE_PARAM
415int yyparse (void *);
416#else
417int yyparse (void);
418#endif
419#endif
420
421int
422yyparse(YYPARSE_PARAM_ARG)
423 YYPARSE_PARAM_DECL
424{
425 register int yystate;
426 register int yyn;
427 register short *yyssp;
428 register YYSTYPE *yyvsp;
429 int yyerrstatus; /* number of tokens to shift before error messages enabled */
430 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
431
432 short yyssa[YYINITDEPTH]; /* the state stack */
433 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
434
435 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
436 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
437
438#ifdef YYLSP_NEEDED
439 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
440 YYLTYPE *yyls = yylsa;
441 YYLTYPE *yylsp;
442
443#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
444#else
445#define YYPOPSTACK (yyvsp--, yyssp--)
446#endif
447
448 int yystacksize = YYINITDEPTH;
449 int yyfree_stacks = 0;
450
451#ifdef YYPURE
452 int yychar;
453 YYSTYPE yylval;
454 int yynerrs;
455#ifdef YYLSP_NEEDED
456 YYLTYPE yylloc;
457#endif
458#endif
459
460 YYSTYPE yyval; /* the variable used to return */
461 /* semantic values from the action */
462 /* routines */
463
464 int yylen;
465
466#if YYDEBUG != 0
467 if (yydebug)
468 fprintf(stderr, "Starting parse\n");
469#endif
470
471 yystate = 0;
472 yyerrstatus = 0;
473 yynerrs = 0;
474 yychar = YYEMPTY; /* Cause a token to be read. */
475
476 /* Initialize stack pointers.
477 Waste one element of value and location stack
478 so that they stay on the same level as the state stack.
479 The wasted elements are never initialized. */
480
481 yyssp = yyss - 1;
482 yyvsp = yyvs;
483#ifdef YYLSP_NEEDED
484 yylsp = yyls;
485#endif
486
487/* Push a new state, which is found in yystate . */
488/* In all cases, when you get here, the value and location stacks
489 have just been pushed. so pushing a state here evens the stacks. */
490yynewstate:
491
492 *++yyssp = yystate;
493
494 if (yyssp >= yyss + yystacksize - 1)
495 {
496 /* Give user a chance to reallocate the stack */
497 /* Use copies of these so that the &'s don't force the real ones into memory. */
498 YYSTYPE *yyvs1 = yyvs;
499 short *yyss1 = yyss;
500#ifdef YYLSP_NEEDED
501 YYLTYPE *yyls1 = yyls;
502#endif
503
504 /* Get the current used size of the three stacks, in elements. */
505 int size = yyssp - yyss + 1;
506
507#ifdef yyoverflow
508 /* Each stack pointer address is followed by the size of
509 the data in use in that stack, in bytes. */
510#ifdef YYLSP_NEEDED
511 /* This used to be a conditional around just the two extra args,
512 but that might be undefined if yyoverflow is a macro. */
513 yyoverflow("parser stack overflow",
514 &yyss1, size * sizeof (*yyssp),
515 &yyvs1, size * sizeof (*yyvsp),
516 &yyls1, size * sizeof (*yylsp),
517 &yystacksize);
518#else
519 yyoverflow("parser stack overflow",
520 &yyss1, size * sizeof (*yyssp),
521 &yyvs1, size * sizeof (*yyvsp),
522 &yystacksize);
523#endif
524
525 yyss = yyss1; yyvs = yyvs1;
526#ifdef YYLSP_NEEDED
527 yyls = yyls1;
528#endif
529#else /* no yyoverflow */
530 /* Extend the stack our own way. */
531 if (yystacksize >= YYMAXDEPTH)
532 {
533 yyerror("parser stack overflow");
534 if (yyfree_stacks)
535 {
536 free (yyss);
537 free (yyvs);
538#ifdef YYLSP_NEEDED
539 free (yyls);
540#endif
541 }
542 return 2;
543 }
544 yystacksize *= 2;
545 if (yystacksize > YYMAXDEPTH)
546 yystacksize = YYMAXDEPTH;
547#ifndef YYSTACK_USE_ALLOCA
548 yyfree_stacks = 1;
549#endif
550 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
551 __yy_memcpy ((char *)yyss, (char *)yyss1,
552 size * (unsigned int) sizeof (*yyssp));
553 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
554 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
555 size * (unsigned int) sizeof (*yyvsp));
556#ifdef YYLSP_NEEDED
557 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
558 __yy_memcpy ((char *)yyls, (char *)yyls1,
559 size * (unsigned int) sizeof (*yylsp));
560#endif
561#endif /* no yyoverflow */
562
563 yyssp = yyss + size - 1;
564 yyvsp = yyvs + size - 1;
565#ifdef YYLSP_NEEDED
566 yylsp = yyls + size - 1;
567#endif
568
569#if YYDEBUG != 0
570 if (yydebug)
571 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
572#endif
573
574 if (yyssp >= yyss + yystacksize - 1)
575 YYABORT;
576 }
577
578#if YYDEBUG != 0
579 if (yydebug)
580 fprintf(stderr, "Entering state %d\n", yystate);
581#endif
582
583 goto yybackup;
584 yybackup:
585
586/* Do appropriate processing given the current state. */
587/* Read a lookahead token if we need one and don't already have one. */
588/* yyresume: */
589
590 /* First try to decide what to do without reference to lookahead token. */
591
592 yyn = yypact[yystate];
593 if (yyn == YYFLAG)
594 goto yydefault;
595
596 /* Not known => get a lookahead token if don't already have one. */
597
598 /* yychar is either YYEMPTY or YYEOF
599 or a valid token in external form. */
600
601 if (yychar == YYEMPTY)
602 {
603#if YYDEBUG != 0
604 if (yydebug)
605 fprintf(stderr, "Reading a token: ");
606#endif
607 yychar = YYLEX;
608 }
609
610 /* Convert token to internal form (in yychar1) for indexing tables with */
611
612 if (yychar <= 0) /* This means end of input. */
613 {
614 yychar1 = 0;
615 yychar = YYEOF; /* Don't call YYLEX any more */
616
617#if YYDEBUG != 0
618 if (yydebug)
619 fprintf(stderr, "Now at end of input.\n");
620#endif
621 }
622 else
623 {
624 yychar1 = YYTRANSLATE(yychar);
625
626#if YYDEBUG != 0
627 if (yydebug)
628 {
629 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
630 /* Give the individual parser a way to print the precise meaning
631 of a token, for further debugging info. */
632#ifdef YYPRINT
633 YYPRINT (stderr, yychar, yylval);
634#endif
635 fprintf (stderr, ")\n");
636 }
637#endif
638 }
639
640 yyn += yychar1;
641 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
642 goto yydefault;
643
644 yyn = yytable[yyn];
645
646 /* yyn is what to do for this token type in this state.
647 Negative => reduce, -yyn is rule number.
648 Positive => shift, yyn is new state.
649 New state is final state => don't bother to shift,
650 just return success.
651 0, or most negative number => error. */
652
653 if (yyn < 0)
654 {
655 if (yyn == YYFLAG)
656 goto yyerrlab;
657 yyn = -yyn;
658 goto yyreduce;
659 }
660 else if (yyn == 0)
661 goto yyerrlab;
662
663 if (yyn == YYFINAL)
664 YYACCEPT;
665
666 /* Shift the lookahead token. */
667
668#if YYDEBUG != 0
669 if (yydebug)
670 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
671#endif
672
673 /* Discard the token being shifted unless it is eof. */
674 if (yychar != YYEOF)
675 yychar = YYEMPTY;
676
677 *++yyvsp = yylval;
678#ifdef YYLSP_NEEDED
679 *++yylsp = yylloc;
680#endif
681
682 /* count tokens shifted since error; after three, turn off error status. */
683 if (yyerrstatus) yyerrstatus--;
684
685 yystate = yyn;
686 goto yynewstate;
687
688/* Do the default action for the current state. */
689yydefault:
690
691 yyn = yydefact[yystate];
692 if (yyn == 0)
693 goto yyerrlab;
694
695/* Do a reduction. yyn is the number of a rule to reduce with. */
696yyreduce:
697 yylen = yyr2[yyn];
698 if (yylen > 0)
699 yyval = yyvsp[1-yylen]; /* implement default value of the action */
700
701#if YYDEBUG != 0
702 if (yydebug)
703 {
704 int i;
705
706 fprintf (stderr, "Reducing via rule %d (line %d), ",
707 yyn, yyrline[yyn]);
708
709 /* Print the symbols being reduced, and their result. */
710 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
711 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
712 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
713 }
714#endif
715
716
717 switch (yyn) {
718
719case 1:
720#line 76 "bool_parser.y"
721{ tree_base = yyvsp[0].node;;
722 break;}
723case 2:
724#line 80 "bool_parser.y"
725{ yyval.node = CreateBoolTermNode(term_list, yyvsp[0].text, 1, word_num, count, doc_count, invf_ptr, invf_len, stemmer_num); ;
726 break;}
727case 3:
728#line 81 "bool_parser.y"
729{ yyval.node = yyvsp[-1].node; ;
730 break;}
731case 4:
732#line 82 "bool_parser.y"
733{ yyval.node = CreateBoolTreeNode(N_all, NULL, NULL); ;
734 break;}
735case 5:
736#line 83 "bool_parser.y"
737{ yyval.node = CreateBoolTreeNode(N_none, NULL, NULL); ;
738 break;}
739case 7:
740#line 87 "bool_parser.y"
741{ yyval.node = CreateBoolTreeNode(N_not, yyvsp[0].node, NULL); ;
742 break;}
743case 8:
744#line 90 "bool_parser.y"
745{ yyval.node = CreateBoolTreeNode(N_and, yyvsp[-2].node, yyvsp[0].node); ;
746 break;}
747case 9:
748#line 91 "bool_parser.y"
749{ yyval.node = CreateBoolTreeNode(N_and, yyvsp[-1].node, yyvsp[0].node); ;
750 break;}
751case 11:
752#line 95 "bool_parser.y"
753{ yyval.node = CreateBoolTreeNode(N_or, yyvsp[-2].node, yyvsp[0].node); ;
754 break;}
755}
756 /* the action file gets copied in in place of this dollarsign */
757#line 542 "/usr/share/bison.simple"
758
759
760 yyvsp -= yylen;
761 yyssp -= yylen;
762#ifdef YYLSP_NEEDED
763 yylsp -= yylen;
764#endif
765
766#if YYDEBUG != 0
767 if (yydebug)
768 {
769 short *ssp1 = yyss - 1;
770 fprintf (stderr, "state stack now");
771 while (ssp1 != yyssp)
772 fprintf (stderr, " %d", *++ssp1);
773 fprintf (stderr, "\n");
774 }
775#endif
776
777 *++yyvsp = yyval;
778
779#ifdef YYLSP_NEEDED
780 yylsp++;
781 if (yylen == 0)
782 {
783 yylsp->first_line = yylloc.first_line;
784 yylsp->first_column = yylloc.first_column;
785 yylsp->last_line = (yylsp-1)->last_line;
786 yylsp->last_column = (yylsp-1)->last_column;
787 yylsp->text = 0;
788 }
789 else
790 {
791 yylsp->last_line = (yylsp+yylen-1)->last_line;
792 yylsp->last_column = (yylsp+yylen-1)->last_column;
793 }
794#endif
795
796 /* Now "shift" the result of the reduction.
797 Determine what state that goes to,
798 based on the state we popped back to
799 and the rule number reduced by. */
800
801 yyn = yyr1[yyn];
802
803 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
804 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
805 yystate = yytable[yystate];
806 else
807 yystate = yydefgoto[yyn - YYNTBASE];
808
809 goto yynewstate;
810
811yyerrlab: /* here on detecting error */
812
813 if (! yyerrstatus)
814 /* If not already recovering from an error, report this error. */
815 {
816 ++yynerrs;
817
818#ifdef YYERROR_VERBOSE
819 yyn = yypact[yystate];
820
821 if (yyn > YYFLAG && yyn < YYLAST)
822 {
823 int size = 0;
824 char *msg;
825 int x, count;
826
827 count = 0;
828 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
829 for (x = (yyn < 0 ? -yyn : 0);
830 x < (sizeof(yytname) / sizeof(char *)); x++)
831 if (yycheck[x + yyn] == x)
832 size += strlen(yytname[x]) + 15, count++;
833 msg = (char *) malloc(size + 15);
834 if (msg != 0)
835 {
836 strcpy(msg, "parse error");
837
838 if (count < 5)
839 {
840 count = 0;
841 for (x = (yyn < 0 ? -yyn : 0);
842 x < (sizeof(yytname) / sizeof(char *)); x++)
843 if (yycheck[x + yyn] == x)
844 {
845 strcat(msg, count == 0 ? ", expecting `" : " or `");
846 strcat(msg, yytname[x]);
847 strcat(msg, "'");
848 count++;
849 }
850 }
851 yyerror(msg);
852 free(msg);
853 }
854 else
855 yyerror ("parse error; also virtual memory exceeded");
856 }
857 else
858#endif /* YYERROR_VERBOSE */
859 yyerror("parse error");
860 }
861
862 goto yyerrlab1;
863yyerrlab1: /* here on error raised explicitly by an action */
864
865 if (yyerrstatus == 3)
866 {
867 /* if just tried and failed to reuse lookahead token after an error, discard it. */
868
869 /* return failure if at end of input */
870 if (yychar == YYEOF)
871 YYABORT;
872
873#if YYDEBUG != 0
874 if (yydebug)
875 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
876#endif
877
878 yychar = YYEMPTY;
879 }
880
881 /* Else will try to reuse lookahead token
882 after shifting the error token. */
883
884 yyerrstatus = 3; /* Each real token shifted decrements this */
885
886 goto yyerrhandle;
887
888yyerrdefault: /* current state does not do anything special for the error token. */
889
890#if 0
891 /* This is wrong; only states that explicitly want error tokens
892 should shift them. */
893 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
894 if (yyn) goto yydefault;
895#endif
896
897yyerrpop: /* pop the current state because it cannot handle the error token */
898
899 if (yyssp == yyss) YYABORT;
900 yyvsp--;
901 yystate = *--yyssp;
902#ifdef YYLSP_NEEDED
903 yylsp--;
904#endif
905
906#if YYDEBUG != 0
907 if (yydebug)
908 {
909 short *ssp1 = yyss - 1;
910 fprintf (stderr, "Error: state stack now");
911 while (ssp1 != yyssp)
912 fprintf (stderr, " %d", *++ssp1);
913 fprintf (stderr, "\n");
914 }
915#endif
916
917yyerrhandle:
918
919 yyn = yypact[yystate];
920 if (yyn == YYFLAG)
921 goto yyerrdefault;
922
923 yyn += YYTERROR;
924 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
925 goto yyerrdefault;
926
927 yyn = yytable[yyn];
928 if (yyn < 0)
929 {
930 if (yyn == YYFLAG)
931 goto yyerrpop;
932 yyn = -yyn;
933 goto yyreduce;
934 }
935 else if (yyn == 0)
936 goto yyerrpop;
937
938 if (yyn == YYFINAL)
939 YYACCEPT;
940
941#if YYDEBUG != 0
942 if (yydebug)
943 fprintf(stderr, "Shifting error token, ");
944#endif
945
946 *++yyvsp = yylval;
947#ifdef YYLSP_NEEDED
948 *++yylsp = yylloc;
949#endif
950
951 yystate = yyn;
952 goto yynewstate;
953
954 yyacceptlab:
955 /* YYACCEPT comes here. */
956 if (yyfree_stacks)
957 {
958 free (yyss);
959 free (yyvs);
960#ifdef YYLSP_NEEDED
961 free (yyls);
962#endif
963 }
964 return 0;
965
966 yyabortlab:
967 /* YYABORT comes here. */
968 if (yyfree_stacks)
969 {
970 free (yyss);
971 free (yyvs);
972#ifdef YYLSP_NEEDED
973 free (yyls);
974#endif
975 }
976 return 1;
977}
978#line 99 "bool_parser.y"
979
980
981/* Bison on one mips machine defined "const" to be nothing but
982 then did not undef it */
983#ifdef const
984#undef const
985#endif
986
987/**************************************************************************/
988
989
990/* =========================================================================
991 * Function: query_lex
992 * Description:
993 * Hand written lexical analyser for the parser.
994 * Input:
995 * ptr = ptr to a ptr into character query-line buffer
996 * end = ptr to last char in buffer
997 * Output:
998 * yylval.text = the token's text
999 * Notes:
1000 * does NOT produce WILD tokens at the moment
1001 * ========================================================================= */
1002
1003/* [RPAP - Jan 97: Stem Index Change]
1004 state mode:
1005 0 = Read next token
1006 1 = Output word
1007 2 = Output '|' or ')'
1008 */
1009static int query_lex(char **ptr, const char *end)
1010{
1011 char *buf_ptr = *ptr;
1012 static int mode = 0;
1013 static int termnum = 0;
1014 static TermList *Terms = NULL;
1015
1016 if (mode == 0)
1017 {
1018 /* jump over whitespace */
1019 while (isspace(*buf_ptr))
1020 buf_ptr++;
1021
1022 if (inaword(buf_ptr, end))
1023 {
1024 static char word[MAXSTEMLEN + 1]; /* [RJM 07/98: Memory Leak] */
1025 char *sWord = Xmalloc(MAXSTEMLEN + 1);
1026 int stem_to_apply, method_using = -1;
1027
1028 PARSE_STEM_WORD(word, buf_ptr, end);
1029
1030 /* Extract any parameters */
1031 stem_to_apply = stem_method;
1032 while (buf_ptr <= end)
1033 {
1034 int stem_param, param_type;
1035 char param[MAXPARAMLEN + 1];
1036
1037 param_type = 0;
1038 PARSE_OPT_TERM_PARAM (param, param_type, buf_ptr, end);
1039 if (!param_type)
1040 break;
1041
1042 if (param_type == STEMPARAM)
1043 {
1044 stem_param = atoi (param);
1045 if (errno != ERANGE && indexed && stem_param >= 0 && stem_param <= 3)
1046 method_using = stem_to_apply = stem_param;
1047 }
1048 }
1049
1050 bcopy ((char *) word, (char *) sWord, *word + 1);
1051 stemmer (stem_to_apply, stemmer_num, sWord);
1052
1053 if (stem_to_apply == 0 || !indexed || p__sd == NULL)
1054 {
1055 /* [RPAP - Feb 97: Term Frequency] */
1056 word_num = FindWord (p__sd, sWord, &count, &doc_count, &invf_ptr, &invf_len);
1057 if (word_num == -1)
1058 count = doc_count = invf_ptr = invf_len = 0;
1059 AddQueryTerm (query_term_list, (u_char *) word, count, method_using);
1060
1061 yylval.text = word;
1062 *ptr = buf_ptr; /* fix up ptr */
1063 Xfree (sWord);
1064 return TERM;
1065 }
1066 else
1067 {
1068 *ptr = buf_ptr; /* fix up ptr */
1069 termnum = 0;
1070 ResetTermList (&Terms);
1071 if (FindWords (p__sd, (u_char *) sWord, stem_to_apply, &Terms) > 0)
1072 {
1073 /* [RPAP - Feb 97: Term Frequency] */
1074 int i, freq = 0;
1075 for (i = 0; i < Terms->num; i++)
1076 freq += Terms->TE[i].WE.count;
1077 AddQueryTerm (query_term_list, word, freq, method_using);
1078
1079 Xfree (sWord);
1080 mode = 1;
1081 return '(';
1082 }
1083 else
1084 {
1085 /* Word does not exists - include in tree anyway */
1086 Xfree (sWord);
1087
1088 /* [RPAP - Feb 97: Term Frequency] */
1089 word_num = -1;
1090 count = doc_count = invf_ptr = invf_len = 0;
1091 AddQueryTerm (query_term_list, (u_char *) word, count, method_using);
1092
1093 yylval.text = word;
1094 return TERM;
1095 }
1096 }
1097 }
1098 else /* NON-WORD */
1099 {
1100 if (*buf_ptr == '\0')
1101 {
1102 /* return null-char if it is one */
1103 *ptr = buf_ptr; /* fix up ptr */
1104 return 0;
1105 }
1106 else
1107 {
1108 /* return 1st char, and delete from buffer */
1109 char c = *buf_ptr++;
1110 *ptr = buf_ptr; /* fix up ptr */
1111 return c;
1112 }
1113 }
1114 }
1115 else if (mode == 1)
1116 {
1117 yylval.text = Terms->TE[termnum].Word;
1118
1119 /* [RPAP - Feb 97: Term Frequency] */
1120 word_num = Terms->TE[termnum].WE.word_num;
1121 count = Terms->TE[termnum].WE.count;
1122 doc_count = Terms->TE[termnum].WE.doc_count;
1123 invf_ptr = Terms->TE[termnum].WE.invf_ptr;
1124 invf_len = Terms->TE[termnum].WE.invf_len;
1125
1126 termnum++;
1127 mode = 2;
1128 return TERM;
1129 }
1130 else /* mode == 2 */
1131 {
1132 if (termnum >= Terms->num)
1133 {
1134 mode = 0;
1135 return ')';
1136 }
1137 else
1138 {
1139 mode = 1;
1140 return '|';
1141 }
1142 }
1143}/*query_lex*/
1144
1145/* =========================================================================
1146 * Function: yyerror
1147 * Description:
1148 * Input:
1149 * Output:
1150 * ========================================================================= */
1151static int yyerror(char *s)
1152{
1153 Message("%s", s);
1154 return(1);
1155}
1156
1157
1158/* =========================================================================
1159 * Function: ParseBool
1160 * Description:
1161 * Parse a boolean query string into a term-list and a boolean parse tree
1162 * Input:
1163 * query_line = query line string
1164 * query_len = query line length
1165 * the_stem_method = stem method id used for stemming
1166 * Output:
1167 * the_term_list = the list of terms
1168 * res = parser result code
1169 * ========================================================================= */
1170
1171bool_tree_node *
1172ParseBool(char *query_line, int query_len,
1173 TermList **the_term_list, int the_stemmer_num, int the_stem_method, int *res,
1174 stemmed_dict * the_sd, int is_indexed, /* [RPAP - Jan 97: Stem Index Change] */
1175 QueryTermList **the_query_term_list) /* [RPAP - Feb 97: Term Frequency] */
1176{
1177 /* global variables to be accessed by bison/yacc created parser */
1178 term_list = the_term_list;
1179 stemmer_num = the_stemmer_num;
1180 stem_method = the_stem_method;
1181 ch_buf = query_line;
1182 end_buf = query_line + query_len;
1183 p__sd = the_sd; /* [RPAP - Jan 97: Stem Index Change] */
1184 indexed = is_indexed; /* [RPAP - Jan 97: Stem Index Change] */
1185 query_term_list = the_query_term_list; /* [RPAP - Feb 97: Term Frequency] */
1186
1187 FreeBoolTree(&(tree_base));
1188
1189 ResetTermList(term_list);
1190 ResetQueryTermList(query_term_list); /* [RPAP - Feb 97: Term Frequency] */
1191
1192 *res = yyparse();
1193
1194 return tree_base;
1195}
1196
1197
Note: See TracBrowser for help on using the repository browser.