parse.y revision 1.2 1 /* $NetBSD: parse.y,v 1.2 1997/11/09 20:59:16 phil 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 MENU NEXT EXIT ACTION ENDWIN OPTION TITLE
59 %token <i_value> DEFAULT DISPLAY ERROR
60 %token <s_value> STRING NAME CODE INT_CONST CHAR_CONST
61
62 %type <s_value> init_code system
63 %type <optn_value> option option_list
64 %type <i_value> act_opt
65 %type <a_value> action exitact
66
67 %start system
68
69 %%
70
71 system : init_code menu_list
72 { check_defined();
73 if (!had_errors)
74 write_menu_file($1);
75 }
76 ;
77
78 init_code : /* empty */ { $$ = ""; }
79 | CODE
80 ;
81
82 menu_list : /* empty */
83 | menu_list menu_def
84 | menu_list default_def
85 | menu_list initerror_def
86 ;
87
88 initerror_def : ERROR action ';'
89 { error_act = $2; }
90
91 default_def : DEFAULT
92 { cur_menu = &default_menu; }
93 opt opt_list ";"
94
95 menu_def : MENU NAME
96 { cur_menu = get_menu ($2);
97 if (cur_menu->info != NULL)
98 yyerror ("Menu %s defined twice", $2);
99 else {
100 cur_menu->info =
101 (menu_info *) malloc (sizeof (menu_info));
102 *(cur_menu->info) = default_info;
103 }
104 }
105 opts ";" dispact option_list exitact
106 { optn_info *t;
107 cur_menu->info->optns = NULL;
108 while ($7 != NULL) {
109 t = $7;
110 $7 = $7->next;
111 t->next = cur_menu->info->optns;
112 cur_menu->info->optns = t;
113 cur_menu->info->numopt++;
114 }
115 }
116 ;
117
118 opts : /* empty */
119 | opt_list
120 ;
121
122 opt_list : "," opt
123 | opt_list "," opt
124 ;
125
126 opt : NO EXIT { cur_menu->info->mopt |= NOEXITOPT; }
127 | NO BOX { cur_menu->info->mopt |= NOBOX; }
128 | EXIT { cur_menu->info->mopt &= ~NOEXITOPT; }
129 | BOX { cur_menu->info->mopt &= ~NOBOX; }
130 | X "=" INT_CONST { cur_menu->info->x = atoi($3); }
131 | Y "=" INT_CONST { cur_menu->info->y = atoi($3); }
132 | W "=" INT_CONST { cur_menu->info->w = atoi($3); }
133 | H "=" INT_CONST { cur_menu->info->h = atoi($3); }
134 | TITLE STRING { cur_menu->info->title = $2; }
135 ;
136
137 option_list : option
138 | option_list option { $2->next = $1; $$ = $2; }
139 ;
140
141 option : OPTION STRING ","
142 { cur_optn = (optn_info *) malloc (sizeof(optn_info));
143 cur_optn->name = $2;
144 cur_optn->menu = -1;
145 cur_optn->issub = FALSE;
146 cur_optn->doexit = FALSE;
147 cur_optn->optact.code = "";
148 cur_optn->optact.endwin = FALSE;
149 cur_optn->next = NULL;
150 }
151 elem_list ";"
152 { $$ = cur_optn; }
153 ;
154
155 elem_list : elem
156 | elem_list "," elem
157 ;
158
159 elem : NEXT MENU NAME
160 { id_rec *t = get_menu ($3);
161 if (cur_optn->menu != -1)
162 yyerror ("Double sub/next menu definition");
163 else {
164 cur_optn->menu = t->menu_no;
165 }
166 }
167 | SUB MENU NAME
168 { id_rec *t = get_menu ($3);
169 if (cur_optn->menu != -1)
170 yyerror ("Double sub/next menu definition");
171 else {
172 cur_optn->menu = t->menu_no;
173 cur_optn->issub = TRUE;
174 }
175 }
176 | action { cur_optn->optact = $1; }
177 | EXIT { cur_optn->doexit = TRUE; }
178 ;
179
180 action : ACTION act_opt CODE
181 { $$.code = $3;
182 $$.endwin = $2;
183 }
184 ;
185
186 act_opt : /* empty */ { $$ = 0; }
187 | "(" ENDWIN ")" { $$ = 1; }
188 ;
189
190 dispact : /* empty */ { cur_menu->info->postact.code = ""; }
191 | DISPLAY action ";" { cur_menu->info->postact = $2; }
192 ;
193
194
195 exitact : /* empty */ { cur_menu->info->exitact.code = ""; }
196 | EXIT action ";" { cur_menu->info->exitact = $2; }
197 ;
198
199