dtinfo other files
[oweals/cde.git] / cde / lib / DtSearch / boolyac.y
1 %{
2 /* $XConsortium: boolyac.y /main/1 1996/03/29 17:04:13 cde-ibm $
3  *
4  * (c) Copyright 1996 Digital Equipment Corporation.
5  * (c) Copyright 1996 Hewlett-Packard Company.
6  * (c) Copyright 1996 International Business Machines Corp.
7  * (c) Copyright 1996 Sun Microsystems, Inc.
8  * (c) Copyright 1996 Novell, Inc. 
9  * (c) Copyright 1996 FUJITSU LIMITED.
10  * (c) Copyright 1996 Hitachi.
11  */
12 /*
13  *   COMPONENT_NAME: austext
14  *
15  *   FUNCTIONS: expr
16  *              yyparse
17  *
18  *   ORIGINS: 27
19  *
20  *
21  *   (C) COPYRIGHT International Business Machines Corp. 1996,1996
22  *   All Rights Reserved
23  *   Licensed Materials - Property of IBM
24  *   US Government Users Restricted Rights - Use, duplication or
25  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
26  */
27 /********************* BOOLYAC.Y ********************
28  * $Id: boolyac.y /main/1 1996/03/29 17:04:13 cde-ibm $
29  * February 1996.
30  * AusText/DtSearch yacc-based boolean query parser.
31  * Converts boolean query into stems array and truth table
32  * for subsequent search.  This is the yacc source.
33  * After processing by yacc, it becomes boolyac.c and boolyac.h.
34  * Boolpars.c contains all the related C source code: yylex,
35  * action functions, and the main driver function, boolean_parse.
36  *
37  * $Log$
38  * Revision 1.1  1996/03/05  15:52:05  miker
39  * Initial revision
40  *
41  */
42 #include <stddef.h>
43 #include "boolpars.h"
44 %}
45
46 %union {
47     TRUTHTAB    *truthtab;
48     int         int_val;
49 }
50
51 %token  <truthtab> WORD_TOKEN
52 %left   '|'             /* left associative, lowest precedence */
53 %left   '&'             /* left associative, higher precedence */
54 %right  '~'             /* right associative */
55 %token  <int_val>  COLLOC_TOKEN
56 %token  ERROR_TOKEN     /* highest precedence */
57
58 %type   <truthtab> expr query
59 %%
60
61 /*********** Top Level Start Rule ****************/
62 query:  /* nothing */
63                 {
64                     if (parser_invalid_wordcount > 0)
65                         add_syntax_errmsg(6);
66                     else
67                         add_syntax_errmsg(1);
68                     YYABORT;
69                 }
70
71   |     expr    
72                 { $$ = copy_final_truthtab ($1); }
73
74   |     '&' expr
75                 { add_syntax_errmsg(2);  YYABORT; }
76
77   |     expr '&'
78                 {
79                     if (qry_is_all_ANDs)
80                         $$ = copy_final_truthtab ($1);
81                     else {
82                         add_syntax_errmsg(2);
83                         YYABORT;
84                     }
85                 }
86
87   |     '|' expr
88                 { add_syntax_errmsg(2);  YYABORT; }
89
90   |     expr '|'
91                 { add_syntax_errmsg(2);  YYABORT; }
92
93   |     '(' ')'
94                 { add_syntax_errmsg(3);  YYABORT; }
95
96   |     expr '~' 
97                 { add_syntax_errmsg(4);  YYABORT; }
98
99   |     COLLOC_TOKEN expr
100                 { add_syntax_errmsg(5);  YYABORT; }
101
102   |     ')' COLLOC_TOKEN
103                 { add_syntax_errmsg(5);  YYABORT; }
104
105   |     ERROR_TOKEN     { YYABORT; }
106   ;
107
108 /*********** Valid Expressions  ************/
109 expr:   WORD_TOKEN
110                 { $$ = $1; }
111
112   |     expr '&' expr
113                 { $$ = boolyac_AND ($1, $3); } 
114
115   |     expr '|' expr
116                 { $$ = boolyac_OR ($1, $3); }
117
118   |     '(' expr ')'
119                 { $$ = $2; }
120
121   |     '~' expr
122                 { $$ = boolyac_NOT ($2); }
123
124   |     WORD_TOKEN COLLOC_TOKEN WORD_TOKEN %prec COLLOC_TOKEN
125                 {
126                     $$ = boolyac_COLLOC ($1, $2, $3);
127                     if ($$ == NULL)
128                         YYABORT;
129                 }
130   ;
131
132 %%
133 /********************* BOOLYAC.Y ********************/
134