2 /* Copyright (C) 1991 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
45 #define input lex_input
46 #define unput lex_unput
50 static boolean ldgram_in_defsym;
51 static boolean ldgram_had_equals;
52 extern boolean ldgram_in_script;
53 static char *command_line;
62 #define RTOKEN(x) { yylval.token = x; return x; }
63 keyword_type keywords[] =
74 "sizeof_headers",SIZEOF_HEADERS,
75 "SIZEOF_HEADERS",SIZEOF_HEADERS,
79 "SEARCH_DIR",SEARCH_DIR,
83 "CREATE_OBJECT_SYMBOLS",CREATE_OBJECT_SYMBOLS,
84 "FORCE_COMMON_ALLOCATION",FORCE_COMMON_ALLOCATION,
88 "OUTPUT_FORMAT",OUTPUT_FORMAT,
89 "OUTPUT_ARCH", OUTPUT_ARCH,
103 extern boolean hex_mode;
104 FILE *ldlex_input_stack;
105 static unsigned int have_pushback;
108 int pushback[NPUSHBACK];
110 extern char *ldfile_input_filename;
115 if (have_pushback > 0)
118 return thischar = pushback[have_pushback];
120 if (ldlex_input_stack) {
121 thischar = fgetc(ldlex_input_stack);
123 if (thischar == EOF) {
124 fclose(ldlex_input_stack);
125 ldlex_input_stack = (FILE *)NULL;
126 ldfile_input_filename = (char *)NULL;
127 /* First char after script eof is a @ so that we can tell the grammer
133 else if (command_line && *command_line) {
134 thischar = *(command_line++);
139 if(thischar == '\t') thischar = ' ';
140 if (thischar == '\n') { thischar = ' '; lineno++; }
148 if (have_pushback > NPUSHBACK) {
149 info("%F%P Too many pushbacks\n");
152 pushback[have_pushback] = c;
166 fprintf(yyout,"%d",x);
173 fprintf(yyout,"%s",x);
198 for (i= 1; i < ac; i++) {
199 size += strlen(av[i]) + 2;
201 dst = p = (char *)ldmalloc(size + 2);
202 /* Put a space arount each option */
205 for (i =1; i < ac; i++) {
207 unsigned int s = strlen(av[i]);
209 memcpy(dst, av[i], s);
222 DEFUN(number,(default_if_zero,base),
223 int default_if_zero AND
229 base = default_if_zero;
244 case '0': case '1': case '2': case '3': case '4':
245 case '5': case '6': case '7': case '8': case '9':
246 l = l * base + ch - '0';
248 case 'a': case 'b': case 'c' : case 'd' : case 'e': case 'f':
249 l =l *base + ch - 'a' + 10;
251 case 'A': case 'B': case 'C' : case 'D' : case 'E': case 'F':
252 l =l *base + ch - 'A' + 10;
266 FILENAMECHAR [a-zA-Z0-9\/\.\-\_\+\=]
267 FILENAME {FILENAMECHAR}+
273 "\ -defsym\ " { ldgram_in_defsym = true; return OPTION_defsym; }
274 "\ -noinhibit_exec\ " { return OPTION_noinhibit_exec; }
275 "\ -sort_common\ " { return OPTION_sort_common;}
276 "\ -format\ " { return OPTION_format; }
277 "\ -n\ " { return OPTION_n; }
278 "\ -r\ " { return OPTION_r; }
279 "\ -i\ " { return OPTION_r; }
280 "\ -Ur\ " { return OPTION_Ur; }
281 "\ -o\ " { return OPTION_o; }
282 "\ -g\ " { return OPTION_g; }
283 "\ -e\ " { return OPTION_e; }
284 "\ -b\ " { return OPTION_b; }
285 "\ -dc\ " { return OPTION_dc; }
286 "\ -dp\ " { return OPTION_dp; }
287 "\ -d\ " { return OPTION_d; }
288 "\ -v\ " { return OPTION_v; }
289 "\ -M\ " { return OPTION_M; }
290 "\ -t\ " { return OPTION_t; }
291 "\ -X\ " { return OPTION_X; }
292 "\ -x\ " { return OPTION_x; }
293 "\ -c\ " { return OPTION_c; }
294 "\ -R\ " { return OPTION_R; }
295 "\ -u\ " { return OPTION_u; }
296 "\ -s\ " { return OPTION_s; }
297 "\ -S\ " { return OPTION_S; }
298 "\ -B{FILENAME}\ " { /* Ignored */ }
300 yylval.name = buystring(yytext+3);
305 yylval.name = buystring(yytext+3);
309 yylval.name = ".text";
313 yylval.name = ".data";
317 yylval.name = ".bss";
321 yylval.name = buystring(yytext+3);
326 yylval.name = buystring(yytext+3);
341 yylval.name = buystring(yytext+3);
346 if (ldgram_had_equals == true) {
347 ldgram_in_defsym = false;
348 ldgram_had_equals = false;
351 "<<=" { RTOKEN(LSHIFTEQ);}
352 ">>=" { RTOKEN(RSHIFTEQ);}
353 "||" { RTOKEN(OROR);}
358 "<<" { RTOKEN(LSHIFT);}
359 ">>" { RTOKEN(RSHIFT);}
360 "+=" { RTOKEN(PLUSEQ);}
361 "-=" { RTOKEN(MINUSEQ);}
362 "*=" { RTOKEN(MULTEQ);}
363 "/=" { RTOKEN(DIVEQ);}
364 "&=" { RTOKEN(ANDEQ);}
365 "|=" { RTOKEN(OREQ);}
366 "&&" { RTOKEN(ANDAND);}
378 "}" { RTOKEN('}') ; }
400 if (input() == '/') {
403 unput(yytext[yyleng-1]);
409 yylval.name = buystring(yytext+1);
410 yylval.name[yyleng-2] = 0; /* Fry final quote */
416 boolean loop = false;
420 /* If we're in hex mode (only after a -T) then all we can see are numbers
421 hex digit we see will be a number. */
424 return number(16, 16);
427 /* If we're in a defsym then all things starting with a digit are in
430 if (isdigit(yytext[0]) && ldgram_in_defsym) {
431 return number(16,16);
435 /* Otherwise if we're in a script we will parse the numbers
438 if (ldgram_in_script == true && isdigit(yytext[0])) {
442 /* Anywhere not in a script or defsym, an opertor is part of a
443 filename, except / and, which is an operator when on its own */
444 if (ldgram_in_script == true|| ldgram_in_defsym == true) {
447 case '*': RTOKEN('*');
450 ldgram_had_equals = true;
455 if (ldgram_in_defsym) RTOKEN('/');
458 case '+': RTOKEN('+');
459 case '-': RTOKEN('-');
460 case '!': RTOKEN('!');
461 case '~': RTOKEN('~');
466 /* Otherwise this must be a file or a symbol name, and it will continue to be a
467 filename until we get to something strange. In scripts operator looking
468 things are taken to be operators, except /, which will be left
473 if (ldgram_in_defsym == true) {
486 if(ldgram_in_script == true) {
498 if (isalpha(ch) || isdigit(ch) || ch == '.' || ch == '_' ||
499 ch == '/' || ch == '.' || ch == '+' || ch == '-' || ch =='=') {
500 yytext[yyleng++] = ch;
510 for(k = keywords; k ->name != (char *)NULL; k++) {
511 if (strcmp(k->name, yytext)==0) {
512 yylval.token = k->value;
516 yylval.name = buystring(yytext);