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