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