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