arparse.y revision 99461
133965Sjdp%{
233965Sjdp/* arparse.y - Stange script language parser */
333965Sjdp
478828Sobrien/*   Copyright 1992, 1993, 1995, 1997, 1999 Free Software Foundation, Inc.
533965Sjdp
633965SjdpThis file is part of GNU Binutils.
733965Sjdp
833965SjdpThis program is free software; you can redistribute it and/or modify
933965Sjdpit under the terms of the GNU General Public License as published by
1033965Sjdpthe Free Software Foundation; either version 2 of the License, or
1133965Sjdp(at your option) any later version.
1233965Sjdp
1333965SjdpThis program is distributed in the hope that it will be useful,
1433965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1533965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1633965SjdpGNU General Public License for more details.
1733965Sjdp
1833965SjdpYou should have received a copy of the GNU General Public License
1933965Sjdpalong with this program; if not, write to the Free Software
2033965SjdpFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2133965Sjdp
2233965Sjdp
2333965Sjdp/* Contributed by Steve Chamberlain
2433965Sjdp   		  sac@cygnus.com
2533965Sjdp
2633965Sjdp*/
2733965Sjdp#define DONTDECLARE_MALLOC
2833965Sjdp#include "bfd.h"
2933965Sjdp#include "bucomm.h"
3033965Sjdp#include "arsup.h"
3133965Sjdpextern int verbose;
3260484Sobrienextern int yylex PARAMS ((void));
3333965Sjdpstatic int yyerror PARAMS ((const char *));
3433965Sjdp%}
3533965Sjdp
3633965Sjdp%union {
3733965Sjdp  char *name;
3833965Sjdpstruct list *list ;
3933965Sjdp
4033965Sjdp};
4133965Sjdp
4233965Sjdp%token NEWLINE
4333965Sjdp%token VERBOSE
4433965Sjdp%token <name> FILENAME
4533965Sjdp%token ADDLIB
4633965Sjdp%token LIST
4733965Sjdp%token ADDMOD
4833965Sjdp%token CLEAR
4933965Sjdp%token CREATE
5033965Sjdp%token DELETE
5133965Sjdp%token DIRECTORY
5233965Sjdp%token END
5333965Sjdp%token EXTRACT
5433965Sjdp%token FULLDIR
5533965Sjdp%token HELP
5633965Sjdp%token QUIT
5733965Sjdp%token REPLACE
5833965Sjdp%token SAVE
5933965Sjdp%token OPEN
6033965Sjdp
6133965Sjdp%type <list> modulelist
6233965Sjdp%type <list> modulename
6333965Sjdp%type <name> optional_filename
6433965Sjdp%%
6533965Sjdp
6633965Sjdpstart:
6733965Sjdp	{ prompt(); } session
6833965Sjdp	;
6933965Sjdp
7033965Sjdpsession:
7133965Sjdp	    session command_line
7233965Sjdp	|
7333965Sjdp	;
7433965Sjdp
7533965Sjdpcommand_line:
7633965Sjdp		command NEWLINE { prompt(); }
7799461Sobrien	;
7833965Sjdp
7933965Sjdpcommand:
8033965Sjdp		open_command
8133965Sjdp	|	create_command
8233965Sjdp	| 	verbose_command
8333965Sjdp	|	directory_command
8433965Sjdp	|	addlib_command
8533965Sjdp	|	clear_command
8633965Sjdp	|	addmod_command
8733965Sjdp	| 	save_command
8833965Sjdp        |       extract_command
8933965Sjdp	|	replace_command
9033965Sjdp	|	delete_command
9133965Sjdp	|	list_command
9233965Sjdp	| 	END	 { ar_end(); return 0; }
9333965Sjdp	| 	error
9433965Sjdp	|       FILENAME { yyerror("foo"); }
9533965Sjdp	|
9633965Sjdp	;
9733965Sjdp
9833965Sjdp
9933965Sjdpextract_command:
10033965Sjdp                EXTRACT modulename
10133965Sjdp		{ ar_extract($2); }
10233965Sjdp	;
10333965Sjdp
10433965Sjdpreplace_command:
10533965Sjdp		REPLACE modulename
10633965Sjdp		{ ar_replace($2); }
10733965Sjdp	;
10833965Sjdp
10933965Sjdpclear_command:
11033965Sjdp		CLEAR
11133965Sjdp		{ ar_clear(); }
11233965Sjdp	;
11333965Sjdp
11433965Sjdpdelete_command:
11533965Sjdp		DELETE modulename
11633965Sjdp		{ ar_delete($2); }
11733965Sjdp	;
11833965Sjdpaddmod_command:
11933965Sjdp	ADDMOD modulename
12033965Sjdp		{ ar_addmod($2); }
12133965Sjdp	;
12233965Sjdp
12333965Sjdplist_command:
12433965Sjdp		LIST
12533965Sjdp		{ ar_list(); }
12633965Sjdp	;
12733965Sjdp
12833965Sjdpsave_command:
12933965Sjdp		SAVE
13033965Sjdp		{ ar_save(); }
13133965Sjdp	;
13233965Sjdp
13333965Sjdp
13433965Sjdp
13533965Sjdpopen_command:
13633965Sjdp		OPEN FILENAME
13733965Sjdp		{ ar_open($2,0); }
13833965Sjdp	;
13933965Sjdp
14033965Sjdpcreate_command:
14133965Sjdp		CREATE FILENAME
14233965Sjdp		{ ar_open($2,1); }
14333965Sjdp	;
14433965Sjdp
14533965Sjdp
14633965Sjdpaddlib_command:
14733965Sjdp		ADDLIB FILENAME modulelist
14833965Sjdp		{ ar_addlib($2,$3); }
14933965Sjdp	;
15033965Sjdpdirectory_command:
15133965Sjdp		DIRECTORY FILENAME modulelist optional_filename
15233965Sjdp		{ ar_directory($2, $3, $4); }
15333965Sjdp	;
15433965Sjdp
15533965Sjdp
15633965Sjdp
15733965Sjdpoptional_filename:
15833965Sjdp		FILENAME
15933965Sjdp		{ $$ = $1; }
16033965Sjdp	|	{ $$ = 0; }
16133965Sjdp	;
16233965Sjdp
16333965Sjdpmodulelist:
16433965Sjdp	'(' modulename ')'
16533965Sjdp		{ $$ = $2; }
16633965Sjdp	|
16733965Sjdp		{ $$ = 0; }
16833965Sjdp	;
16933965Sjdp
17033965Sjdpmodulename:
17133965Sjdp		modulename optcomma FILENAME
17233965Sjdp		{ 	struct list *n  = (struct list *) malloc(sizeof(struct list));
17333965Sjdp			n->next = $1;
17433965Sjdp			n->name = $3;
17533965Sjdp			$$ = n;
17633965Sjdp		 }
17733965Sjdp	|	{ $$ = 0; }
17833965Sjdp	;
17933965Sjdp
18033965Sjdp
18133965Sjdpoptcomma:
18233965Sjdp		','
18333965Sjdp	|
18433965Sjdp	;
18533965Sjdp
18633965Sjdp
18733965Sjdpverbose_command:
18833965Sjdp	VERBOSE
18933965Sjdp		{ verbose = !verbose; }
19033965Sjdp	;
19133965Sjdp
19233965Sjdp
19333965Sjdp%%
19433965Sjdp
19533965Sjdpstatic int
19633965Sjdpyyerror (x)
19760484Sobrien     const char *x ATTRIBUTE_UNUSED;
19833965Sjdp{
19933965Sjdp  extern int linenumber;
20033965Sjdp
20160484Sobrien  printf (_("Syntax error in archive script, line %d\n"), linenumber + 1);
20233965Sjdp  return 0;
20333965Sjdp}
204