bfd/
[binutils.git] / binutils / arparse.y
blob113c5483b914aa780ef2649c4b2b14ed64e1f2f9
1 %{
2 /* arparse.y - Stange script language parser */
4 /* Copyright 1992, 1993, 1995, 1997, 1999, 2002, 2003, 2005, 2007
5 Free Software Foundation, Inc.
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
25 /* Contributed by Steve Chamberlain
26 sac@cygnus.com
29 #define DONTDECLARE_MALLOC
30 #include "sysdep.h"
31 #include "bfd.h"
32 #include "arsup.h"
33 extern int verbose;
34 extern int yylex (void);
35 static int yyerror (const char *);
38 %union {
39 char *name;
40 struct list *list ;
44 %token NEWLINE
45 %token VERBOSE
46 %token <name> FILENAME
47 %token ADDLIB
48 %token LIST
49 %token ADDMOD
50 %token CLEAR
51 %token CREATE
52 %token DELETE
53 %token DIRECTORY
54 %token END
55 %token EXTRACT
56 %token FULLDIR
57 %token HELP
58 %token QUIT
59 %token REPLACE
60 %token SAVE
61 %token OPEN
63 %type <list> modulelist
64 %type <list> modulename
65 %type <name> optional_filename
68 start:
69 { prompt(); } session
72 session:
73 session command_line
77 command_line:
78 command NEWLINE { prompt(); }
81 command:
82 open_command
83 | create_command
84 | verbose_command
85 | directory_command
86 | addlib_command
87 | clear_command
88 | addmod_command
89 | save_command
90 | extract_command
91 | replace_command
92 | delete_command
93 | list_command
94 | END { ar_end(); return 0; }
95 | error
96 | FILENAME { yyerror("foo"); }
101 extract_command:
102 EXTRACT modulename
103 { ar_extract($2); }
106 replace_command:
107 REPLACE modulename
108 { ar_replace($2); }
111 clear_command:
112 CLEAR
113 { ar_clear(); }
116 delete_command:
117 DELETE modulename
118 { ar_delete($2); }
120 addmod_command:
121 ADDMOD modulename
122 { ar_addmod($2); }
125 list_command:
126 LIST
127 { ar_list(); }
130 save_command:
131 SAVE
132 { ar_save(); }
137 open_command:
138 OPEN FILENAME
139 { ar_open($2,0); }
142 create_command:
143 CREATE FILENAME
144 { ar_open($2,1); }
148 addlib_command:
149 ADDLIB FILENAME modulelist
150 { ar_addlib($2,$3); }
152 directory_command:
153 DIRECTORY FILENAME modulelist optional_filename
154 { ar_directory($2, $3, $4); }
159 optional_filename:
160 FILENAME
161 { $$ = $1; }
162 | { $$ = 0; }
165 modulelist:
166 '(' modulename ')'
167 { $$ = $2; }
169 { $$ = 0; }
172 modulename:
173 modulename optcomma FILENAME
174 { struct list *n = (struct list *) malloc(sizeof(struct list));
175 n->next = $1;
176 n->name = $3;
177 $$ = n;
179 | { $$ = 0; }
183 optcomma:
189 verbose_command:
190 VERBOSE
191 { verbose = !verbose; }
197 static int
198 yyerror (const char *x ATTRIBUTE_UNUSED)
200 extern int linenumber;
202 printf (_("Syntax error in archive script, line %d\n"), linenumber + 1);
203 return 0;