xref: /Universal-ctags/Units/parser-yacc.r/nested.d/input.y (revision 3153baba598a37e41716a9873adbcf2596991075)
1 /* Taken from xorg-x11-xkb-utils-7.7/xkbevd-1.1.3/cfgparse.y */
2 /************************************************************
3  Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
4 
5  Permission to use, copy, modify, and distribute this
6  software and its documentation for any purpose and without
7  fee is hereby granted, provided that the above copyright
8  notice appear in all copies and that both that copyright
9  notice and this permission notice appear in supporting
10  documentation, and that the name of Silicon Graphics not be
11  used in advertising or publicity pertaining to distribution
12  of the software without specific prior written permission.
13  Silicon Graphics makes no representation about the suitability
14  of this software for any purpose. It is provided "as is"
15  without any express or implied warranty.
16 
17  SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
18  SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19  AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
20  GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
21  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22  DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
23  OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
24  THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 
26  ********************************************************/
27 
28 %token
29 	END_OF_FILE	0
30 	ERROR		255
31 	BELL		1
32 	ACCESSX		2
33 	MESSAGE		3
34 
35 	NONE		20
36 	IGNORE		21
37 	ECHO		22
38 	PRINT_EV	23
39 	SHELL		24
40 	SOUND		25
41 
42 	EQUALS		40
43 	PLUS		41
44 	MINUS		42
45 	DIVIDE		43
46 	TIMES		44
47 	OBRACE		45
48 	CBRACE		46
49 	OPAREN		47
50 	CPAREN		48
51 	OBRACKET	49
52 	CBRACKET	50
53 	DOT		51
54 	COMMA		52
55 	SEMI		53
56 	EXCLAM		54
57 	INVERT		55
58 	STRING		60
59 	INTEGER		61
60 	FLOAT		62
61 	IDENT		63
62 	KEYNAME		64
63 %{
64 #ifdef DEBUG
65 #define	YYDEBUG 1
66 #endif
67 #define	DEBUG_VAR parseDebug
68 #include "xkbevd.h"
69 #include <stdlib.h>
70 %}
71 %right	EQUALS
72 %left	PLUS MINUS
73 %left	TIMES DIVIDE
74 %left	EXCLAM INVERT
75 %left	OPAREN
76 %start	CfgFile
77 %union	{
78 	char *		str;
79 	int		ival;
80 	CfgEntryPtr	entry;
81 	ActDefPtr	act;
82 }
83 %type <str>	Ident String OptString NameSpec OptNameSpec
84 %type <ival>	ActionType EventType
85 %type <act>	ActionDef
86 %type <entry>	CfgFile CfgEntryList CfgEntry EventDef VarDef
87 %%
88 CfgFile
89 		:	CfgEntryList
90 			{ InterpretConfigs($1); }
91 		;
92 
93 CfgEntryList	:	CfgEntryList CfgEntry
94 			{
95 			    CfgEntryPtr tmp;
96 			    if ($1!=NULL) {
97 				for (tmp=$1;tmp->next!=NULL;tmp=tmp->next) {
98 				    /* conditional does the work */
99 				}
100 				tmp->next= $2;
101 				$$= $1;
102 			    }
103 			    else $$= $2;
104 			}
105 		|	CfgEntry { $$= $1; }
106 		;
107 
108 CfgEntry	:	EventDef ActionDef
109 			{
110 			    if (($1)&&($2))
111 				$1->action= *($2);
112 			    if ($2)
113 				free($2);
114 			    $$= $1;
115 			}
116 		|	VarDef 		{ $$= $1; }
117 		;
118 
119 VarDef		:	Ident EQUALS NameSpec
120 			{
121 			    CfgEntryPtr cfg;
122 			    cfg= calloc(1,sizeof(CfgEntryRec));
123 			    if (cfg) {
124 				cfg->entry_type= VariableDef;
125 				cfg->event_type= 0;
126 				cfg->name.str= $1;
127 				cfg->action.type= UnknownAction;
128 				cfg->action.text= $3;
129 				cfg->action.priv= 0;
130 				cfg->next= NULL;
131 			    }
132 			    $$= cfg;
133 			}
134 		;
135 
136 EventDef	:	EventType OPAREN OptNameSpec CPAREN
137 			{
138 			    CfgEntryPtr cfg;
139 			    cfg= calloc(1,sizeof(CfgEntryRec));
140 			    if (cfg) {
141 				cfg->entry_type= EventDef;
142 				cfg->event_type= $1;
143 				cfg->name.str= $3;
144 				cfg->action.type= UnknownAction;
145 				cfg->action.text= NULL;
146 				cfg->action.priv= 0;
147 				cfg->next= NULL;
148 			    }
149 			    $$= cfg;
150 			}
151 		;
152 
153 EventType	:	BELL		{ $$= XkbBellNotify; }
154 		|	ACCESSX		{ $$= XkbAccessXNotify; }
155 		|	MESSAGE		{ $$= XkbActionMessage; }
156 		;
157 
158 ActionDef	:	ActionType OptString
159 			{
160 			    ActDefPtr act;
161 			    act= calloc(1,sizeof(ActDefRec));
162 			    if (act) {
163 				act->type= $1;
164 				act->text= $2;
165 			    }
166 			    $$= act;
167 			}
168 		;
169 
170 ActionType	:	NONE	 { $$ = NoAction; }
171 		|	IGNORE	 { $$ = NoAction; }
172 		|	ECHO	 { $$ = EchoAction; }
173 		|	PRINT_EV { $$ = PrintEvAction; }
174 		|	SHELL	 { $$ = ShellAction; }
175 		|	SOUND	 { $$ = SoundAction; }
176 		|		 { $$ = UnknownAction; }
177 		;
178 
179 OptNameSpec	:	NameSpec { $$= $1; }
180 		|		 { $$= NULL; }
181 		;
182 
183 NameSpec	:	Ident	{ $$= $1; }
184 		|	String	{ $$= $1; }
185 		;
186 
187 Ident		:	IDENT	{ $$= scanStr; scanStr= NULL; }
188 		;
189 
190 OptString	:	String	{ $$= $1; }
191 		|		{ $$= NULL; }
192 		;
193 
194 String		:	STRING	{ $$= scanStr; scanStr= NULL; }
195 		;
196 %%
197 int
198 yyerror(char *s)
199 {
200     (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
201 					(scanFile?scanFile:"(unknown)"));
202     if (scanStr)
203 	(void)fprintf(stderr,"last scanned symbol is: %s\n",scanStr);
204     return 1;
205 }
206 
207 
208 int
yywrap(void)209 yywrap(void)
210 {
211    return 1;
212 }
213 
214 int
CFGParseFile(FILE * file)215 CFGParseFile(FILE *file)
216 {
217     if (file) {
218 	yyin= file;
219 	if (yyparse()==0) {
220 	    return 1;
221 	}
222 	return 0;
223     }
224     return 1;
225 }
226