parse.y revision 1.10 1 /* $NetBSD: parse.y,v 1.10 2003/05/07 16:39:45 dsl Exp $ */
2
3 /*
4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved.
6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software develooped for the NetBSD Project by
20 * Piermont Information Systems Inc.
21 * 4. The name of Piermont Information Systems Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
39
40 %{
41
42 #include <stdio.h>
43 #include "defs.h"
44
45 static id_rec *cur_menu;
46 static optn_info *cur_optn;
47
48 %}
49
50 %union {
51 char *s_value;
52 int i_value;
53 optn_info *optn_value;
54 action a_value;
55 }
56
57
58 %token <i_value> X Y W H NO BOX SUB HELP MENU NEXT EXIT ACTION ENDWIN OPTION
59 %token <i_value> TITLE DEFAULT DISPLAY ERROR EXITSTRING ALLOW DYNAMIC MENUS
60 SCROLLABLE SHORTCUT
61 %token <s_value> STRING NAME CODE INT_CONST CHAR_CONST
62
63 %type <s_value> init_code system helpstr
64 %type <optn_value> option option_list
65 %type <i_value> act_opt
66 %type <a_value> action exitact
67
68 %start system
69
70 %%
71
72 system : init_code menu_list
73 { check_defined();
74 if (!had_errors)
75 write_menu_file($1);
76 }
77 ;
78
79 init_code : /* empty */ { $$ = ""; }
80 | CODE
81 ;
82
83 menu_list : /* empty */
84 | menu_list menu_def
85 | menu_list default_def
86 | menu_list initerror_def
87 | menu_list dynamic_def
88 ;
89
90 dynamic_def : ALLOW DYNAMIC MENUS ';'
91 { do_dynamic = 1; }
92
93 initerror_def : ERROR action ';'
94 { error_act = $2; }
95
96 default_def : DEFAULT
97 { cur_menu = &default_menu; }
98 opt opt_list ";"
99
100 menu_def : MENU NAME
101 { cur_menu = get_menu ($2);
102 if (cur_menu->info != NULL)
103 yyerror ("Menu %s defined twice", $2);
104 else {
105 cur_menu->info =
106 (menu_info *) malloc (sizeof (menu_info));
107 *(cur_menu->info) = default_info;
108 }
109 }
110 opts ";" dispact option_list exitact helpstr
111 { optn_info *t;
112 cur_menu->info->optns = NULL;
113 while ($7 != NULL) {
114 t = $7;
115 $7 = $7->next;
116 t->next = cur_menu->info->optns;
117 cur_menu->info->optns = t;
118 cur_menu->info->numopt++;
119 }
120 }
121 ;
122
123 opts : /* empty */
124 | opt_list
125 ;
126
127 opt_list : "," opt
128 | opt_list "," opt
129 ;
130
131 opt : NO EXIT { cur_menu->info->mopt |= NOEXITOPT; }
132 | EXIT { cur_menu->info->mopt &= ~NOEXITOPT; }
133 | NO BOX { cur_menu->info->mopt |= NOBOX; }
134 | BOX { cur_menu->info->mopt &= ~NOBOX; }
135 | NO SCROLLABLE { cur_menu->info->mopt &= ~SCROLL; }
136 | SCROLLABLE { cur_menu->info->mopt |= SCROLL; }
137 | NO SHORTCUT { cur_menu->info->mopt |= NOSHORTCUT; }
138 | SHORTCUT { cur_menu->info->mopt &= ~NOSHORTCUT; }
139 | X "=" INT_CONST { cur_menu->info->x = atoi($3); }
140 | Y "=" INT_CONST { cur_menu->info->y = atoi($3); }
141 | W "=" INT_CONST { cur_menu->info->w = atoi($3); }
142 | H "=" INT_CONST { cur_menu->info->h = atoi($3); }
143 | TITLE STRING { cur_menu->info->title = $2; }
144 | EXITSTRING STRING { cur_menu->info->exitstr = $2;
145 cur_menu->info->mopt &= ~NOEXITOPT; }
146 ;
147
148 option_list : option
149 | option_list option { $2->next = $1; $$ = $2; }
150 ;
151
152 option : OPTION STRING ","
153 { cur_optn = (optn_info *) malloc (sizeof(optn_info));
154 cur_optn->name = $2;
155 cur_optn->menu = -1;
156 cur_optn->issub = FALSE;
157 cur_optn->doexit = FALSE;
158 cur_optn->optact.code = "";
159 cur_optn->optact.endwin = FALSE;
160 cur_optn->next = NULL;
161 }
162 elem_list ";"
163 { $$ = cur_optn; }
164 ;
165
166 elem_list : elem
167 | elem_list "," elem
168 ;
169
170 elem : NEXT MENU NAME
171 { id_rec *t = get_menu ($3);
172 if (cur_optn->menu != -1)
173 yyerror ("Double sub/next menu definition");
174 else {
175 cur_optn->menu = t->menu_no;
176 }
177 }
178 | SUB MENU NAME
179 { id_rec *t = get_menu ($3);
180 if (cur_optn->menu != -1)
181 yyerror ("Double sub/next menu definition");
182 else {
183 cur_optn->menu = t->menu_no;
184 cur_optn->issub = TRUE;
185 }
186 }
187 | action { cur_optn->optact = $1; }
188 | EXIT { cur_optn->doexit = TRUE; }
189 ;
190
191 action : ACTION act_opt CODE
192 { $$.code = $3;
193 $$.endwin = $2;
194 }
195 ;
196
197 act_opt : /* empty */ { $$ = 0; }
198 | "(" ENDWIN ")" { $$ = 1; }
199 ;
200
201 dispact : /* empty */ { cur_menu->info->postact.code = ""; }
202 | DISPLAY action ";" { cur_menu->info->postact = $2; }
203 ;
204
205
206 exitact : /* empty */ { cur_menu->info->exitact.code = ""; }
207 | EXIT action ";" { cur_menu->info->exitact = $2; }
208 ;
209
210 helpstr : /* empty */ { cur_menu->info->helpstr = NULL; }
211 | HELP CODE ";" { cur_menu->info->helpstr = $2; }
212 ;
213