bfd/
[deliverable/binutils-gdb.git] / binutils / defparse.y
1 %{ /* defparse.y - parser for .def files */
2
3 /* Copyright 1995, 1997, 1998, 1999, 2001, 2004, 2007
4 Free Software Foundation, Inc.
5
6 This file is part of GNU Binutils.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libiberty.h"
25 #include "dlltool.h"
26 %}
27
28 %union {
29 char *id;
30 int number;
31 };
32
33 %token NAME LIBRARY DESCRIPTION STACKSIZE HEAPSIZE CODE DATA
34 %token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANT
35 %token READ WRITE EXECUTE SHARED NONSHARED NONAME PRIVATE
36 %token SINGLE MULTIPLE INITINSTANCE INITGLOBAL TERMINSTANCE TERMGLOBAL
37 %token <id> ID
38 %token <number> NUMBER
39 %type <number> opt_base opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
40 %type <number> attr attr_list opt_number
41 %type <id> opt_name opt_equal_name
42
43 %%
44
45 start: start command
46 | command
47 ;
48
49 command:
50 NAME opt_name opt_base { def_name ($2, $3); }
51 | LIBRARY opt_name opt_base option_list { def_library ($2, $3); }
52 | EXPORTS explist
53 | DESCRIPTION ID { def_description ($2);}
54 | STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);}
55 | HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
56 | CODE attr_list { def_code ($2);}
57 | DATA attr_list { def_data ($2);}
58 | SECTIONS seclist
59 | IMPORTS implist
60 | VERSIONK NUMBER { def_version ($2,0);}
61 | VERSIONK NUMBER '.' NUMBER { def_version ($2,$4);}
62 ;
63
64
65 explist:
66 /* EMPTY */
67 | explist expline
68 ;
69
70 expline:
71 ID opt_equal_name opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
72 { def_exports ($1, $2, $3, $4, $5, $6, $7);}
73 ;
74 implist:
75 implist impline
76 | impline
77 ;
78
79 impline:
80 ID '=' ID '.' ID '.' ID { def_import ($1,$3,$5,$7, 0); }
81 | ID '=' ID '.' ID '.' NUMBER { def_import ($1,$3,$5, 0,$7); }
82 | ID '=' ID '.' ID { def_import ($1,$3, 0,$5, 0); }
83 | ID '=' ID '.' NUMBER { def_import ($1,$3, 0, 0,$5); }
84 | ID '.' ID '.' ID { def_import ( 0,$1,$3,$5, 0); }
85 | ID '.' ID '.' NUMBER { def_import ( 0,$1,$3, 0,$5); }
86 | ID '.' ID { def_import ( 0,$1, 0,$3, 0); }
87 | ID '.' NUMBER { def_import ( 0,$1, 0, 0,$3); }
88 ;
89
90 seclist:
91 seclist secline
92 | secline
93 ;
94
95 secline:
96 ID attr_list { def_section ($1,$2);}
97 ;
98
99 attr_list:
100 attr_list opt_comma attr
101 | attr
102 ;
103
104 opt_comma:
105 ','
106 |
107 ;
108 opt_number: ',' NUMBER { $$=$2;}
109 | { $$=-1;}
110 ;
111
112 attr:
113 READ { $$ = 1; }
114 | WRITE { $$ = 2; }
115 | EXECUTE { $$ = 4; }
116 | SHARED { $$ = 8; }
117 | NONSHARED { $$ = 0; }
118 | SINGLE { $$ = 0; }
119 | MULTIPLE { $$ = 0; }
120 ;
121
122 opt_CONSTANT:
123 CONSTANT {$$=1;}
124 | {$$=0;}
125 ;
126
127 opt_NONAME:
128 NONAME {$$=1;}
129 | {$$=0;}
130 ;
131
132 opt_DATA:
133 DATA { $$ = 1; }
134 | { $$ = 0; }
135 ;
136
137 opt_PRIVATE:
138 PRIVATE { $$ = 1; }
139 | { $$ = 0; }
140 ;
141
142 opt_name: ID { $$ =$1; }
143 | ID '.' ID
144 {
145 char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
146 sprintf (name, "%s.%s", $1, $3);
147 $$ = name;
148 }
149 | { $$=""; }
150 ;
151
152 opt_ordinal:
153 '@' NUMBER { $$=$2;}
154 | { $$=-1;}
155 ;
156
157 opt_equal_name:
158 '=' ID { $$ = $2; }
159 | '=' ID '.' ID
160 {
161 char *name = xmalloc (strlen ($2) + 1 + strlen ($4) + 1);
162 sprintf (name, "%s.%s", $2, $4);
163 $$ = name;
164 }
165 | { $$ = 0; }
166 ;
167
168 opt_base: BASE '=' NUMBER { $$= $3;}
169 | { $$=-1;}
170 ;
171
172 option_list:
173 /* empty */
174 | option_list opt_comma option
175 ;
176
177 option:
178 INITINSTANCE
179 | INITGLOBAL
180 | TERMINSTANCE
181 | TERMGLOBAL
182 ;
This page took 0.038113 seconds and 5 git commands to generate.