Commit | Line | Data |
---|---|---|
2fa0b342 | 1 | %{ |
0d3e45ea | 2 | |
c477527c | 3 | /* Copyright (C) 1991, 1993 Free Software Foundation, Inc. |
2fa0b342 DHW |
4 | |
5 | This file is part of GLD, the Gnu Linker. | |
6 | ||
7 | GLD is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
2e2bf962 | 9 | the Free Software Foundation; either version 2, or (at your option) |
2fa0b342 DHW |
10 | any later version. |
11 | ||
12 | GLD is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GLD; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* | |
9d1fe8a4 SC |
22 | This was written by steve chamberlain |
23 | sac@cygnus.com | |
2fa0b342 DHW |
24 | */ |
25 | ||
26 | ||
9d1fe8a4 | 27 | #include <ansidecl.h> |
fcf276c4 | 28 | #include <stdio.h> |
b5b2c886 SS |
29 | /* start-sanitize-mpw */ |
30 | #ifdef MPW | |
31 | /* Prevent enum redefinition problems. */ | |
32 | #define TRUE_FALSE_ALREADY_DEFINED | |
33 | #endif /* MPW */ | |
34 | /* end-sanitize-mpw */ | |
a02945df | 35 | #include "bfd.h" |
c477527c | 36 | #include "sysdep.h" |
fcf276c4 | 37 | #include "ld.h" |
9d1fe8a4 | 38 | #include "ldgram.h" |
fcf276c4 ILT |
39 | #include "ldmisc.h" |
40 | #include "ldexp.h" | |
41 | #include "ldlang.h" | |
42 | #include "ldfile.h" | |
9f629407 | 43 | #include "ldlex.h" |
2fa0b342 | 44 | |
9d1fe8a4 | 45 | int ldgram_in_defsym; |
2fa0b342 | 46 | |
9d1fe8a4 | 47 | int hex_mode; |
2e2bf962 | 48 | |
dc4726c2 | 49 | unsigned int lineno = 1; |
9d1fe8a4 | 50 | int old; |
1d45ccb3 | 51 | |
9d1fe8a4 SC |
52 | #undef YY_INPUT |
53 | #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size) | |
54 | #undef YY_FATAL_ERROR | |
fcf276c4 | 55 | #define YY_FATAL_ERROR(s) |
9d1fe8a4 SC |
56 | #define MAX_INCLUDE_DEPTH 10 |
57 | YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; | |
dadd414a | 58 | char *file_name_stack[MAX_INCLUDE_DEPTH]; |
9d1fe8a4 | 59 | unsigned int include_stack_ptr = 0; |
2fa0b342 | 60 | |
fcf276c4 ILT |
61 | static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string, |
62 | int size)); | |
63 | static void yy_input PARAMS ((char *, int *result, int max_size)); | |
64 | static void comment PARAMS ((void)); | |
2fa0b342 | 65 | |
3d2b83ea | 66 | /* STATES |
9d1fe8a4 SC |
67 | COMMAND on command line |
68 | COMMENT in a C comment | |
69 | EXPRESSION definiatelyt in an expression | |
70 | SCRIPT definately in a script | |
71 | SOMEWHERE either EXPRESSION or SCRIPT | |
3d2b83ea | 72 | MRI in an MRI script |
9d1fe8a4 | 73 | */ |
2fa0b342 | 74 | #define RTOKEN(x) { yylval.token = x; return x; } |
9d1fe8a4 | 75 | %} |
2fa0b342 | 76 | |
9d1fe8a4 SC |
77 | %a 4000 |
78 | %o 5000 | |
ee0c4cf7 | 79 | |
6bf2e3a7 SC |
80 | CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~] |
81 | CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~] | |
82 | FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~] | |
0d3e45ea | 83 | SYMBOLCHARN [_a-zA-Z\/\.\\0-9] |
6bf2e3a7 | 84 | FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~] |
9d1fe8a4 SC |
85 | FILENAME {FILENAMECHAR}+ |
86 | WHITE [ \t\n]+ | |
2fa0b342 | 87 | |
85e38cfa SC |
88 | NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~] |
89 | ||
90 | ||
91e25b4f PB |
91 | %s COMMAND |
92 | %s SCRIPT | |
93 | %s EXPRESSION | |
94 | %s COMMENT | |
95 | %s BOTH | |
96 | %s DEFSYMEXP | |
97 | %s MRI | |
9d1fe8a4 | 98 | %% |
91e25b4f | 99 | |
6bf2e3a7 SC |
100 | |
101 | <BOTH,SCRIPT,EXPRESSION,COMMAND>"/*" { comment(); } | |
102 | ||
103 | ||
0d3e45ea SC |
104 | <DEFSYMEXP>"-" { RTOKEN('-');} |
105 | <DEFSYMEXP>"+" { RTOKEN('+');} | |
106 | <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; } | |
107 | <DEFSYMEXP>[ \t] { RTOKEN(DEFSYMEND); } | |
108 | <DEFSYMEXP>"=" { RTOKEN('='); } | |
a02945df KR |
109 | <COMMAND>"--help" { return OPTION_help; } |
110 | <COMMAND>"--version" { return OPTION_version; } | |
0d3e45ea | 111 | <COMMAND>"-defsym"{WHITE}* { return OPTION_defsym; } |
a02945df | 112 | <COMMAND>"-format" { return OPTION_format; } |
9d1fe8a4 | 113 | <COMMAND>"-noinhibit-exec" { return OPTION_noinhibit_exec; } |
a02945df KR |
114 | <COMMAND>"-noinhibit_exec" { return OPTION_noinhibit_exec; } |
115 | <COMMAND>"-oformat" { return OPTION_oformat; } | |
9d1fe8a4 | 116 | <COMMAND>"-sort-common" { return OPTION_sort_common;} |
a02945df | 117 | <COMMAND>"-sort_common" { return OPTION_sort_common;} |
2a28d8b0 | 118 | <COMMAND>"-warn-common" { return OPTION_warn_common;} |
9d1fe8a4 SC |
119 | <COMMAND>"-n" { return OPTION_n; } |
120 | <COMMAND>"-N" { return OPTION_N; } | |
121 | <COMMAND>"-r" { return OPTION_r; } | |
c477527c ILT |
122 | <COMMAND>"-stats" { return OPTION_stats; } |
123 | <COMMAND>"-no-keep-memory" { return OPTION_no_keep_memory; } | |
9d1fe8a4 SC |
124 | <COMMAND>"-relax" { return OPTION_relax; } |
125 | <COMMAND>"-i" { return OPTION_r; } | |
126 | <COMMAND>"-Ur" { return OPTION_Ur; } | |
127 | <COMMAND>"-o" { return OPTION_o; } | |
128 | <COMMAND>"-g" { return OPTION_g; } | |
129 | <COMMAND>"-e" { return OPTION_e; } | |
b5b2c886 SS |
130 | <COMMAND>"-e"{FILENAME} { |
131 | yylval.name = buystring(yytext+2); | |
132 | return OPTION_esymbol; | |
133 | } | |
9d1fe8a4 SC |
134 | <COMMAND>"-b" { return OPTION_b; } |
135 | <COMMAND>"-dc" { return OPTION_dc; } | |
136 | <COMMAND>"-dp" { return OPTION_dp; } | |
137 | <COMMAND>"-d" { return OPTION_d; } | |
138 | <COMMAND>"-v" { return OPTION_v; } | |
139 | <COMMAND>"-V" { return OPTION_V; } | |
8ddef552 DM |
140 | <COMMAND>"-m" { return OPTION_m; } |
141 | <COMMAND>"-m"{FILENAME} { return OPTION_memul; } | |
9d1fe8a4 SC |
142 | <COMMAND>"-M" { return OPTION_M; } |
143 | <COMMAND>"-Map" { return OPTION_Map;} | |
144 | <COMMAND>"-t" { return OPTION_t; } | |
145 | <COMMAND>"-X" { return OPTION_X; } | |
146 | <COMMAND>"-x" { return OPTION_x; } | |
147 | <COMMAND>"-c" { return OPTION_c; } | |
148 | <COMMAND>"-R" { return OPTION_R; } | |
149 | <COMMAND>"-u" { return OPTION_u; } | |
b5b2c886 SS |
150 | <COMMAND>"-u"{FILENAME} { |
151 | yylval.name = buystring(yytext+2); | |
152 | return OPTION_usymbol; | |
153 | } | |
9d1fe8a4 SC |
154 | <COMMAND>"-s" { return OPTION_s; } |
155 | <COMMAND>"-S" { return OPTION_S; } | |
156 | <COMMAND>"-Bstat" { return OPTION_Bstatic; } | |
157 | <COMMAND>"-B"{FILENAME} { /* Ignored */ } | |
158 | <COMMAND>"-l"{FILENAME} { | |
159 | yylval.name = buystring(yytext+2); | |
160 | return OPTION_l; | |
161 | } | |
162 | ||
163 | <COMMAND>"-L"{FILENAME} { | |
164 | yylval.name = buystring(yytext+2); | |
2a28d8b0 | 165 | return OPTION_Lfile; |
9d1fe8a4 | 166 | } |
2a28d8b0 | 167 | <COMMAND>"-L" { return OPTION_L; } |
9d1fe8a4 SC |
168 | <COMMAND>"-Ttext" { |
169 | yylval.name = ".text"; | |
170 | return OPTION_Texp; | |
171 | } | |
172 | <COMMAND>"-Tdata" { | |
173 | yylval.name = ".data"; | |
174 | return OPTION_Texp; | |
175 | } | |
176 | <COMMAND>"-Tbss" { | |
177 | yylval.name = ".bss"; | |
178 | return OPTION_Texp; | |
179 | } | |
fcf276c4 ILT |
180 | <COMMAND>"-O"([0-9])+ { |
181 | yylval.integer = atoi (yytext + 2); | |
182 | return OPTION_Oval; | |
183 | } | |
9d1fe8a4 SC |
184 | <COMMAND>"-O"{FILENAME} { |
185 | yylval.name = buystring(yytext+2); | |
186 | return OPTION_Texp; | |
187 | } | |
188 | ||
189 | <COMMAND>"-T"{FILENAME} { | |
190 | yylval.name = buystring(yytext+2); | |
191 | return OPTION_Tfile; | |
192 | } | |
193 | <COMMAND>"-T" { | |
194 | return OPTION_T; | |
195 | } | |
196 | ||
197 | <COMMAND>"-F"{FILENAME} { | |
198 | return OPTION_F; | |
199 | } | |
200 | <COMMAND>"-F" { | |
201 | return OPTION_F; | |
202 | } | |
203 | ||
b5b2c886 SS |
204 | <COMMAND>"-y" { |
205 | return OPTION_y; | |
206 | } | |
207 | ||
85e38cfa SC |
208 | <COMMAND>"-y"{FILENAME} { |
209 | yylval.name = buystring(yytext+2); | |
b5b2c886 | 210 | return OPTION_ysymbol; |
85e38cfa SC |
211 | } |
212 | ||
9d1fe8a4 SC |
213 | <COMMAND>"-A"{FILENAME} { |
214 | yylval.name = buystring(yytext+2); | |
215 | return OPTION_Aarch; | |
216 | } | |
3d2b83ea | 217 | |
85e38cfa SC |
218 | <COMMAND>"-retain-symbols-file" { return OPTION_RETAIN_SYMBOLS_FILE; } |
219 | ||
8ddef552 DM |
220 | <COMMAND>"-EB" { |
221 | return OPTION_EB; | |
222 | } | |
223 | <COMMAND>"-EL" { | |
224 | return OPTION_EL; | |
225 | } | |
226 | <COMMAND>"-G" { | |
227 | return OPTION_G; | |
228 | } | |
229 | <COMMAND>"-G"([0-9])+ { | |
230 | yylval.integer = atoi (yytext + 2); | |
231 | return OPTION_Gval; | |
232 | } | |
2a28d8b0 DM |
233 | |
234 | <COMMAND>"-Qy" { return OPTION_Qy; } | |
235 | <COMMAND>"-dn" { return OPTION_dn; } | |
236 | <COMMAND>"-Y" { return OPTION_Y; } | |
237 | <COMMAND>"-YP,"{FILENAME} { | |
238 | yylval.name = buystring (yytext+4); | |
239 | return OPTION_YP; | |
240 | } | |
f651733a ILT |
241 | <COMMAND>"-non_shared" { return OPTION_non_shared; } |
242 | <COMMAND>"-call_shared" { return OPTION_call_shared; } | |
2a28d8b0 | 243 | |
3d2b83ea | 244 | <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ { |
f651733a | 245 | yylval.integer = bfd_scan_vma (yytext+1, 0,16); |
3d2b83ea SC |
246 | return INT; |
247 | } | |
248 | ||
91e25b4f | 249 | <MRI,EXPRESSION>([0-9A-Fa-f])+(H|X|B|O|D) { |
9f629407 | 250 | int ibase ; |
3d2b83ea SC |
251 | switch (yytext[yyleng-1]) { |
252 | case 'X': | |
253 | case 'H': | |
9f629407 | 254 | ibase = 16; |
3d2b83ea SC |
255 | break; |
256 | case 'O': | |
9f629407 | 257 | ibase = 8; |
3d2b83ea SC |
258 | break; |
259 | case 'B': | |
9f629407 | 260 | ibase = 2; |
3d2b83ea SC |
261 | break; |
262 | default: | |
9f629407 | 263 | ibase = 10; |
3d2b83ea | 264 | } |
f651733a | 265 | yylval.integer = bfd_scan_vma (yytext+1, 0, |
9f629407 | 266 | ibase); |
3d2b83ea SC |
267 | return INT; |
268 | } | |
9fce28ed | 269 | <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? { |
f651733a ILT |
270 | yylval.integer = bfd_scan_vma (yytext, 0, |
271 | hex_mode); | |
9d1fe8a4 SC |
272 | if (yytext[yyleng-1]=='M' |
273 | || yytext[yyleng-1] == 'm') { | |
274 | yylval.integer *= 1024*1024; | |
275 | } | |
276 | if (yytext[yyleng-1]=='K' | |
277 | || yytext[yyleng-1]=='k') { | |
278 | yylval.integer *= 1024; | |
279 | } | |
280 | return INT; | |
281 | } | |
282 | <BOTH,SCRIPT,EXPRESSION>"]" { RTOKEN(']');} | |
283 | <BOTH,SCRIPT,EXPRESSION>"[" { RTOKEN('[');} | |
284 | <BOTH,SCRIPT,EXPRESSION>"<<=" { RTOKEN(LSHIFTEQ);} | |
285 | <BOTH,SCRIPT,EXPRESSION>">>=" { RTOKEN(RSHIFTEQ);} | |
286 | <BOTH,SCRIPT,EXPRESSION>"||" { RTOKEN(OROR);} | |
287 | <BOTH,SCRIPT,EXPRESSION>"==" { RTOKEN(EQ);} | |
288 | <BOTH,SCRIPT,EXPRESSION>"!=" { RTOKEN(NE);} | |
289 | <BOTH,SCRIPT,EXPRESSION>">=" { RTOKEN(GE);} | |
290 | <BOTH,SCRIPT,EXPRESSION>"<=" { RTOKEN(LE);} | |
291 | <BOTH,SCRIPT,EXPRESSION>"<<" { RTOKEN(LSHIFT);} | |
292 | <BOTH,SCRIPT,EXPRESSION>">>" { RTOKEN(RSHIFT);} | |
293 | <BOTH,SCRIPT,EXPRESSION>"+=" { RTOKEN(PLUSEQ);} | |
294 | <BOTH,SCRIPT,EXPRESSION>"-=" { RTOKEN(MINUSEQ);} | |
295 | <BOTH,SCRIPT,EXPRESSION>"*=" { RTOKEN(MULTEQ);} | |
296 | <BOTH,SCRIPT,EXPRESSION>"/=" { RTOKEN(DIVEQ);} | |
297 | <BOTH,SCRIPT,EXPRESSION>"&=" { RTOKEN(ANDEQ);} | |
298 | <BOTH,SCRIPT,EXPRESSION>"|=" { RTOKEN(OREQ);} | |
299 | <BOTH,SCRIPT,EXPRESSION>"&&" { RTOKEN(ANDAND);} | |
300 | <BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');} | |
3d2b83ea | 301 | <MRI,BOTH,SCRIPT,EXPRESSION>"," { RTOKEN(',');} |
9d1fe8a4 SC |
302 | <BOTH,SCRIPT,EXPRESSION>"&" { RTOKEN('&');} |
303 | <BOTH,SCRIPT,EXPRESSION>"|" { RTOKEN('|');} | |
304 | <BOTH,SCRIPT,EXPRESSION>"~" { RTOKEN('~');} | |
305 | <BOTH,SCRIPT,EXPRESSION>"!" { RTOKEN('!');} | |
306 | <BOTH,SCRIPT,EXPRESSION>"?" { RTOKEN('?');} | |
307 | <BOTH,SCRIPT,EXPRESSION>"*" { RTOKEN('*');} | |
308 | <BOTH,SCRIPT,EXPRESSION>"+" { RTOKEN('+');} | |
309 | <BOTH,SCRIPT,EXPRESSION>"-" { RTOKEN('-');} | |
310 | <BOTH,SCRIPT,EXPRESSION>"/" { RTOKEN('/');} | |
311 | <BOTH,SCRIPT,EXPRESSION>"%" { RTOKEN('%');} | |
312 | <BOTH,SCRIPT,EXPRESSION>"<" { RTOKEN('<');} | |
313 | <BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');} | |
3d2b83ea | 314 | <MRI,BOTH,SCRIPT,EXPRESSION>"=" { RTOKEN('=');} |
9d1fe8a4 SC |
315 | <BOTH,SCRIPT,EXPRESSION>"}" { RTOKEN('}') ; } |
316 | <BOTH,SCRIPT,EXPRESSION>"{" { RTOKEN('{'); } | |
317 | <BOTH,SCRIPT,EXPRESSION>")" { RTOKEN(')');} | |
318 | <BOTH,SCRIPT,EXPRESSION>"(" { RTOKEN('(');} | |
319 | <BOTH,SCRIPT,EXPRESSION>"]" { RTOKEN(']');} | |
320 | <BOTH,SCRIPT,EXPRESSION>"[" { RTOKEN('[');} | |
321 | <BOTH,SCRIPT,EXPRESSION>":" { RTOKEN(':'); } | |
322 | <BOTH,SCRIPT,EXPRESSION>";" { RTOKEN(';');} | |
323 | <BOTH,SCRIPT,EXPRESSION>"-" { RTOKEN('-');} | |
324 | <BOTH,SCRIPT,EXPRESSION>"/" { RTOKEN('/');} | |
325 | <BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);} | |
326 | <BOTH,SCRIPT>"ORIGIN" { RTOKEN(ORIGIN);} | |
327 | <BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);} | |
328 | <BOTH,SCRIPT>"LENGTH" { RTOKEN(LENGTH);} | |
329 | <EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);} | |
330 | <EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);} | |
331 | <BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);} | |
332 | <EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);} | |
333 | <EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);} | |
334 | <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);} | |
335 | <BOTH,SCRIPT>"MAP" { RTOKEN(MAP);} | |
336 | <EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);} | |
337 | <BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);} | |
338 | <BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);} | |
339 | <BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);} | |
340 | <BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);} | |
dadd414a | 341 | <EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);} |
9d1fe8a4 SC |
342 | <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);} |
343 | <BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);} | |
344 | <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);} | |
345 | <BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);} | |
346 | <BOTH,SCRIPT>"FILL" { RTOKEN(FILL);} | |
347 | <BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);} | |
348 | <BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);} | |
349 | <BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);} | |
350 | <BOTH,SCRIPT>"HLL" { RTOKEN(HLL);} | |
351 | <BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);} | |
352 | <BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);} | |
c477527c | 353 | <BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);} |
9d1fe8a4 SC |
354 | <BOTH,SCRIPT>"LONG" { RTOKEN( LONG);} |
355 | <BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);} | |
356 | <BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);} | |
357 | <BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);} | |
dadd414a | 358 | <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);} |
9d1fe8a4 SC |
359 | <BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);} |
360 | <BOTH,SCRIPT>"COPY" { RTOKEN(COPY);} | |
361 | <BOTH,SCRIPT>"INFO" { RTOKEN(INFO);} | |
362 | <BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);} | |
363 | <BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);} | |
364 | <BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);} | |
365 | <BOTH,SCRIPT>"l" { RTOKEN( LENGTH);} | |
366 | <BOTH,SCRIPT>"len" { RTOKEN( LENGTH);} | |
dadd414a | 367 | <BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);} |
9fce28ed | 368 | <EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);} |
2e38b71d | 369 | <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); } |
91e25b4f | 370 | <MRI>"*".* { /* Mri comment line */ } |
2e38b71d | 371 | <MRI>"END" { RTOKEN(ENDWORD); } |
85e38cfa SC |
372 | <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);} |
373 | <MRI>"ALIGN" { RTOKEN(ALIGN_K);} | |
374 | ||
3d2b83ea | 375 | <MRI>"CHIP" { RTOKEN(CHIP); } |
91e25b4f PB |
376 | <MRI>"BASE" { RTOKEN(BASE); } |
377 | <MRI>"ALIAS" { RTOKEN(ALIAS); } | |
85e38cfa | 378 | <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); } |
3d2b83ea | 379 | <MRI>"LOAD" { RTOKEN(LOAD); } |
91e25b4f | 380 | <MRI>"PUBLIC" { RTOKEN(PUBLIC); } |
2e38b71d SC |
381 | <MRI>"ORDER" { RTOKEN(ORDER); } |
382 | <MRI>"NAME" { RTOKEN(NAMEWORD); } | |
383 | <MRI>"FORMAT" { RTOKEN(FORMAT); } | |
384 | <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ } | |
3d2b83ea | 385 | <MRI>"SECT" { RTOKEN(SECT); } |
6bf2e3a7 | 386 | <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); } |
1bd1fa2d SC |
387 | <MRI>"end" { RTOKEN(ENDWORD); } |
388 | <MRI>"chip" { RTOKEN(CHIP); } | |
389 | <MRI>"load" { RTOKEN(LOAD); } | |
390 | <MRI>"order" { RTOKEN(ORDER); } | |
391 | <MRI>"name" { RTOKEN(NAMEWORD); } | |
392 | <MRI>"format" { RTOKEN(FORMAT); } | |
393 | <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ } | |
394 | <MRI>"sect" { RTOKEN(SECT); } | |
6bf2e3a7 | 395 | <EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); } |
3d2b83ea | 396 | |
ee0c4cf7 SC |
397 | <COMMAND>{CMDFILENAMECHAR1}{CMDFILENAMECHAR}* { |
398 | yylval.name = buystring(yytext); | |
399 | return NAME; | |
400 | } | |
401 | ||
402 | ||
85e38cfa SC |
403 | <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* { |
404 | /* Filename without commas, needed to parse mri stuff */ | |
405 | yylval.name = buystring(yytext); | |
406 | return NAME; | |
407 | } | |
408 | ||
409 | ||
410 | <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* { | |
9d1fe8a4 SC |
411 | yylval.name = buystring(yytext); |
412 | return NAME; | |
413 | } | |
414 | <SCRIPT,COMMAND>{FILENAMECHAR}* { yylval.name = buystring(yytext); | |
415 | return NAME; | |
416 | } | |
417 | ||
418 | <EXPRESSION,BOTH,COMMAND,SCRIPT>"\""[^\"]*"\"" { | |
419 | /* No matter the state, quotes | |
420 | give what's inside */ | |
421 | yylval.name = buystring(yytext+1); | |
422 | yylval.name[yyleng-2] = 0; | |
423 | return NAME; | |
424 | } | |
425 | <BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;} | |
3d2b83ea | 426 | <MRI,COMMAND,BOTH,SCRIPT,EXPRESSION>[ \t] |
9d1fe8a4 | 427 | |
9d1fe8a4 | 428 | <<EOF>> { |
dadd414a | 429 | include_stack_ptr--; |
9d1fe8a4 | 430 | |
dadd414a SC |
431 | if (include_stack_ptr == 0) |
432 | { | |
433 | yyterminate(); | |
434 | } | |
435 | else | |
436 | { | |
437 | yy_switch_to_buffer(include_stack[include_stack_ptr]); | |
438 | ||
439 | } | |
440 | if (include_stack_ptr==1) | |
441 | { | |
442 | BEGIN(COMMAND); | |
443 | } | |
444 | else | |
445 | { | |
9fce28ed | 446 | BEGIN(SCRIPT); |
dadd414a | 447 | ldfile_input_filename = file_name_stack[include_stack_ptr-1]; |
2fa0b342 | 448 | } |
dadd414a SC |
449 | |
450 | return END; | |
451 | } | |
9d1fe8a4 | 452 | |
9d1fe8a4 | 453 | %% |
2fa0b342 DHW |
454 | |
455 | void | |
8ddef552 DM |
456 | lex_push_file (file, name) |
457 | FILE *file; | |
458 | char *name; | |
2fa0b342 | 459 | { |
9d1fe8a4 SC |
460 | if (include_stack_ptr >= MAX_INCLUDE_DEPTH) |
461 | { | |
8bf66be8 | 462 | einfo("%F:includes nested too deeply\n"); |
2fa0b342 | 463 | } |
dadd414a SC |
464 | file_name_stack[include_stack_ptr] = name; |
465 | include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; | |
466 | ||
467 | include_stack_ptr++; | |
9d1fe8a4 SC |
468 | yyin = file; |
469 | yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); | |
2fa0b342 | 470 | |
9d1fe8a4 | 471 | BEGIN(SCRIPT); |
2fa0b342 DHW |
472 | } |
473 | ||
fcf276c4 | 474 | static YY_BUFFER_STATE |
8ddef552 DM |
475 | yy_create_string_buffer (string, size) |
476 | CONST char *string; | |
477 | int size; | |
2fa0b342 | 478 | { |
9d1fe8a4 | 479 | YY_BUFFER_STATE b; |
2fa0b342 | 480 | |
9d1fe8a4 SC |
481 | b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) ); |
482 | b->yy_input_file = 0; | |
483 | ||
484 | if ( ! b ) | |
485 | YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); | |
2fa0b342 | 486 | |
9d1fe8a4 | 487 | b->yy_buf_size = size; |
2fa0b342 | 488 | |
9d1fe8a4 SC |
489 | /* yy_ch_buf has to be 2 characters longer than the size given because |
490 | * we need to put in 2 end-of-buffer characters. | |
491 | */ | |
492 | b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 3) ); | |
2fa0b342 | 493 | |
9d1fe8a4 SC |
494 | if ( ! b->yy_ch_buf ) |
495 | YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); | |
2fa0b342 DHW |
496 | |
497 | ||
9d1fe8a4 SC |
498 | b->yy_ch_buf[0] = '\n'; |
499 | strcpy(b->yy_ch_buf+1, string); | |
500 | b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR; | |
501 | b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR; | |
502 | b->yy_n_chars = size+1; | |
503 | b->yy_buf_pos = &b->yy_ch_buf[1]; | |
2fa0b342 | 504 | |
9d1fe8a4 | 505 | b->yy_eof_status = EOF_NOT_SEEN; |
2fa0b342 | 506 | |
9d1fe8a4 | 507 | return ( b ); |
2fa0b342 | 508 | } |
2fa0b342 | 509 | |
2fa0b342 | 510 | |
1418c83b | 511 | |
9d1fe8a4 | 512 | void |
8ddef552 DM |
513 | lex_redirect (string) |
514 | CONST char *string; | |
9d1fe8a4 SC |
515 | { |
516 | YY_BUFFER_STATE tmp; | |
1d45ccb3 | 517 | |
9d1fe8a4 | 518 | int len = strlen(string); |
dadd414a | 519 | yy_init = 0 ; |
9d1fe8a4 SC |
520 | if (include_stack_ptr >= MAX_INCLUDE_DEPTH) |
521 | { | |
8bf66be8 | 522 | einfo("%F: macros nested too deeply\n"); |
1418c83b | 523 | } |
dadd414a SC |
524 | file_name_stack[include_stack_ptr] = "redirect"; |
525 | include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; | |
526 | include_stack_ptr++; | |
9d1fe8a4 SC |
527 | tmp = yy_create_string_buffer(string, len); |
528 | ||
529 | yy_switch_to_buffer(tmp); | |
530 | BEGIN(COMMAND); | |
dadd414a | 531 | yyout = stdout; |
9d1fe8a4 | 532 | } |
1d45ccb3 | 533 | |
9d1fe8a4 SC |
534 | int state_stack[20]; |
535 | int *state_stack_p = state_stack; | |
1d45ccb3 | 536 | |
9d1fe8a4 | 537 | void |
8ddef552 | 538 | ldlex_script () |
9d1fe8a4 | 539 | { |
dadd414a | 540 | *(state_stack_p)++ = yy_start; |
1d45ccb3 | 541 | |
dadd414a | 542 | BEGIN(SCRIPT); |
9d1fe8a4 | 543 | } |
1418c83b | 544 | |
2fa0b342 | 545 | |
3d2b83ea | 546 | void |
8ddef552 | 547 | ldlex_mri_script () |
3d2b83ea | 548 | { |
dadd414a SC |
549 | *(state_stack_p)++ = yy_start; |
550 | BEGIN(MRI); | |
0d3e45ea SC |
551 | } |
552 | ||
553 | void | |
8ddef552 | 554 | ldlex_defsym () |
0d3e45ea | 555 | { |
dadd414a SC |
556 | *(state_stack_p)++ = yy_start; |
557 | BEGIN(DEFSYMEXP); | |
3d2b83ea SC |
558 | } |
559 | ||
9d1fe8a4 | 560 | void |
8ddef552 | 561 | ldlex_expression () |
9d1fe8a4 | 562 | { |
dadd414a SC |
563 | *(state_stack_p)++ = yy_start; |
564 | BEGIN(EXPRESSION); | |
1d45ccb3 | 565 | |
9d1fe8a4 SC |
566 | } |
567 | void | |
8ddef552 | 568 | ldlex_both () |
9d1fe8a4 | 569 | { |
dadd414a SC |
570 | *(state_stack_p)++ = yy_start; |
571 | BEGIN(BOTH); | |
9d1fe8a4 SC |
572 | } |
573 | void | |
8ddef552 | 574 | ldlex_command () |
9d1fe8a4 | 575 | { |
dadd414a SC |
576 | *(state_stack_p)++ = yy_start; |
577 | BEGIN(COMMAND); | |
2fa0b342 DHW |
578 | } |
579 | ||
9d1fe8a4 | 580 | void |
8ddef552 | 581 | ldlex_popstate () |
9d1fe8a4 | 582 | { |
dadd414a | 583 | yy_start = *(--state_stack_p); |
9d1fe8a4 | 584 | } |
2fa0b342 | 585 | |
fcf276c4 | 586 | static void |
9d1fe8a4 SC |
587 | yy_input(buf, result, max_size) |
588 | char *buf; | |
589 | int *result; | |
590 | int max_size; | |
591 | { | |
592 | *result = 0; | |
593 | if (yy_current_buffer->yy_input_file) | |
594 | { | |
595 | if (yyin) | |
596 | if ( (*result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) | |
597 | YY_FATAL_ERROR( "read() in flex scanner failed" ); | |
598 | } | |
599 | } | |
6bf2e3a7 | 600 | |
fcf276c4 ILT |
601 | static void |
602 | comment () | |
85e38cfa SC |
603 | { |
604 | int c; | |
605 | while (1) | |
606 | { | |
607 | c = input(); | |
608 | while (c !='*' && c != EOF) | |
609 | { | |
610 | if (c == '\n') lineno++; | |
611 | c = input(); | |
612 | } | |
613 | ||
614 | ||
615 | if (c == '*') | |
616 | { | |
617 | c = input(); | |
618 | while ( c == '*') | |
619 | c = input(); | |
620 | if ( c == '/' ) | |
621 | break; /* found the end */ | |
622 | } | |
623 | ||
624 | if ( c == EOF ) | |
625 | { | |
8bf66be8 | 626 | einfo( "%F%P :EOF in comment\n"); |
85e38cfa SC |
627 | break; |
628 | } | |
629 | } | |
630 | } |