xref: /openbsd-src/gnu/usr.bin/binutils-2.17/binutils/arparse.y (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod %{
2*3d8817e4Smiod /* arparse.y - Stange script language parser */
3*3d8817e4Smiod 
4*3d8817e4Smiod /*   Copyright 1992, 1993, 1995, 1997, 1999, 2002, 2003
5*3d8817e4Smiod      Free Software Foundation, Inc.
6*3d8817e4Smiod 
7*3d8817e4Smiod This file is part of GNU Binutils.
8*3d8817e4Smiod 
9*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
10*3d8817e4Smiod it under the terms of the GNU General Public License as published by
11*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or
12*3d8817e4Smiod (at your option) any later version.
13*3d8817e4Smiod 
14*3d8817e4Smiod This program is distributed in the hope that it will be useful,
15*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
16*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*3d8817e4Smiod GNU General Public License for more details.
18*3d8817e4Smiod 
19*3d8817e4Smiod You should have received a copy of the GNU General Public License
20*3d8817e4Smiod along with this program; if not, write to the Free Software
21*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
22*3d8817e4Smiod 
23*3d8817e4Smiod 
24*3d8817e4Smiod /* Contributed by Steve Chamberlain
25*3d8817e4Smiod    		  sac@cygnus.com
26*3d8817e4Smiod 
27*3d8817e4Smiod */
28*3d8817e4Smiod #define DONTDECLARE_MALLOC
29*3d8817e4Smiod #include "bfd.h"
30*3d8817e4Smiod #include "bucomm.h"
31*3d8817e4Smiod #include "arsup.h"
32*3d8817e4Smiod extern int verbose;
33*3d8817e4Smiod extern int yylex (void);
34*3d8817e4Smiod static int yyerror (const char *);
35*3d8817e4Smiod %}
36*3d8817e4Smiod 
37*3d8817e4Smiod %union {
38*3d8817e4Smiod   char *name;
39*3d8817e4Smiod struct list *list ;
40*3d8817e4Smiod 
41*3d8817e4Smiod };
42*3d8817e4Smiod 
43*3d8817e4Smiod %token NEWLINE
44*3d8817e4Smiod %token VERBOSE
45*3d8817e4Smiod %token <name> FILENAME
46*3d8817e4Smiod %token ADDLIB
47*3d8817e4Smiod %token LIST
48*3d8817e4Smiod %token ADDMOD
49*3d8817e4Smiod %token CLEAR
50*3d8817e4Smiod %token CREATE
51*3d8817e4Smiod %token DELETE
52*3d8817e4Smiod %token DIRECTORY
53*3d8817e4Smiod %token END
54*3d8817e4Smiod %token EXTRACT
55*3d8817e4Smiod %token FULLDIR
56*3d8817e4Smiod %token HELP
57*3d8817e4Smiod %token QUIT
58*3d8817e4Smiod %token REPLACE
59*3d8817e4Smiod %token SAVE
60*3d8817e4Smiod %token OPEN
61*3d8817e4Smiod 
62*3d8817e4Smiod %type <list> modulelist
63*3d8817e4Smiod %type <list> modulename
64*3d8817e4Smiod %type <name> optional_filename
65*3d8817e4Smiod %%
66*3d8817e4Smiod 
67*3d8817e4Smiod start:
68*3d8817e4Smiod 	{ prompt(); } session
69*3d8817e4Smiod 	;
70*3d8817e4Smiod 
71*3d8817e4Smiod session:
72*3d8817e4Smiod 	    session command_line
73*3d8817e4Smiod 	|
74*3d8817e4Smiod 	;
75*3d8817e4Smiod 
76*3d8817e4Smiod command_line:
77*3d8817e4Smiod 		command NEWLINE { prompt(); }
78*3d8817e4Smiod 	;
79*3d8817e4Smiod 
80*3d8817e4Smiod command:
81*3d8817e4Smiod 		open_command
82*3d8817e4Smiod 	|	create_command
83*3d8817e4Smiod 	| 	verbose_command
84*3d8817e4Smiod 	|	directory_command
85*3d8817e4Smiod 	|	addlib_command
86*3d8817e4Smiod 	|	clear_command
87*3d8817e4Smiod 	|	addmod_command
88*3d8817e4Smiod 	| 	save_command
89*3d8817e4Smiod         |       extract_command
90*3d8817e4Smiod 	|	replace_command
91*3d8817e4Smiod 	|	delete_command
92*3d8817e4Smiod 	|	list_command
93*3d8817e4Smiod 	| 	END	 { ar_end(); return 0; }
94*3d8817e4Smiod 	| 	error
95*3d8817e4Smiod 	|       FILENAME { yyerror("foo"); }
96*3d8817e4Smiod 	|
97*3d8817e4Smiod 	;
98*3d8817e4Smiod 
99*3d8817e4Smiod 
100*3d8817e4Smiod extract_command:
101*3d8817e4Smiod                 EXTRACT modulename
102*3d8817e4Smiod 		{ ar_extract($2); }
103*3d8817e4Smiod 	;
104*3d8817e4Smiod 
105*3d8817e4Smiod replace_command:
106*3d8817e4Smiod 		REPLACE modulename
107*3d8817e4Smiod 		{ ar_replace($2); }
108*3d8817e4Smiod 	;
109*3d8817e4Smiod 
110*3d8817e4Smiod clear_command:
111*3d8817e4Smiod 		CLEAR
112*3d8817e4Smiod 		{ ar_clear(); }
113*3d8817e4Smiod 	;
114*3d8817e4Smiod 
115*3d8817e4Smiod delete_command:
116*3d8817e4Smiod 		DELETE modulename
117*3d8817e4Smiod 		{ ar_delete($2); }
118*3d8817e4Smiod 	;
119*3d8817e4Smiod addmod_command:
120*3d8817e4Smiod 	ADDMOD modulename
121*3d8817e4Smiod 		{ ar_addmod($2); }
122*3d8817e4Smiod 	;
123*3d8817e4Smiod 
124*3d8817e4Smiod list_command:
125*3d8817e4Smiod 		LIST
126*3d8817e4Smiod 		{ ar_list(); }
127*3d8817e4Smiod 	;
128*3d8817e4Smiod 
129*3d8817e4Smiod save_command:
130*3d8817e4Smiod 		SAVE
131*3d8817e4Smiod 		{ ar_save(); }
132*3d8817e4Smiod 	;
133*3d8817e4Smiod 
134*3d8817e4Smiod 
135*3d8817e4Smiod 
136*3d8817e4Smiod open_command:
137*3d8817e4Smiod 		OPEN FILENAME
138*3d8817e4Smiod 		{ ar_open($2,0); }
139*3d8817e4Smiod 	;
140*3d8817e4Smiod 
141*3d8817e4Smiod create_command:
142*3d8817e4Smiod 		CREATE FILENAME
143*3d8817e4Smiod 		{ ar_open($2,1); }
144*3d8817e4Smiod 	;
145*3d8817e4Smiod 
146*3d8817e4Smiod 
147*3d8817e4Smiod addlib_command:
148*3d8817e4Smiod 		ADDLIB FILENAME modulelist
149*3d8817e4Smiod 		{ ar_addlib($2,$3); }
150*3d8817e4Smiod 	;
151*3d8817e4Smiod directory_command:
152*3d8817e4Smiod 		DIRECTORY FILENAME modulelist optional_filename
153*3d8817e4Smiod 		{ ar_directory($2, $3, $4); }
154*3d8817e4Smiod 	;
155*3d8817e4Smiod 
156*3d8817e4Smiod 
157*3d8817e4Smiod 
158*3d8817e4Smiod optional_filename:
159*3d8817e4Smiod 		FILENAME
160*3d8817e4Smiod 		{ $$ = $1; }
161*3d8817e4Smiod 	|	{ $$ = 0; }
162*3d8817e4Smiod 	;
163*3d8817e4Smiod 
164*3d8817e4Smiod modulelist:
165*3d8817e4Smiod 	'(' modulename ')'
166*3d8817e4Smiod 		{ $$ = $2; }
167*3d8817e4Smiod 	|
168*3d8817e4Smiod 		{ $$ = 0; }
169*3d8817e4Smiod 	;
170*3d8817e4Smiod 
171*3d8817e4Smiod modulename:
172*3d8817e4Smiod 		modulename optcomma FILENAME
173*3d8817e4Smiod 		{ 	struct list *n  = (struct list *) malloc(sizeof(struct list));
174*3d8817e4Smiod 			n->next = $1;
175*3d8817e4Smiod 			n->name = $3;
176*3d8817e4Smiod 			$$ = n;
177*3d8817e4Smiod 		 }
178*3d8817e4Smiod 	|	{ $$ = 0; }
179*3d8817e4Smiod 	;
180*3d8817e4Smiod 
181*3d8817e4Smiod 
182*3d8817e4Smiod optcomma:
183*3d8817e4Smiod 		','
184*3d8817e4Smiod 	|
185*3d8817e4Smiod 	;
186*3d8817e4Smiod 
187*3d8817e4Smiod 
188*3d8817e4Smiod verbose_command:
189*3d8817e4Smiod 	VERBOSE
190*3d8817e4Smiod 		{ verbose = !verbose; }
191*3d8817e4Smiod 	;
192*3d8817e4Smiod 
193*3d8817e4Smiod 
194*3d8817e4Smiod %%
195*3d8817e4Smiod 
196*3d8817e4Smiod static int
197*3d8817e4Smiod yyerror (const char *x ATTRIBUTE_UNUSED)
198*3d8817e4Smiod {
199*3d8817e4Smiod   extern int linenumber;
200*3d8817e4Smiod 
201*3d8817e4Smiod   printf (_("Syntax error in archive script, line %d\n"), linenumber + 1);
202*3d8817e4Smiod   return 0;
203*3d8817e4Smiod }
204