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