* ldmain.c (add_wrap): New function.
[deliverable/binutils-gdb.git] / ld / ldlex.l
CommitLineData
2fa0b342 1%{
0d3e45ea 2
fb55f9b8 3/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
2fa0b342
DHW
4
5This file is part of GLD, the Gnu Linker.
6
7GLD is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
2e2bf962 9the Free Software Foundation; either version 2, or (at your option)
2fa0b342
DHW
10any later version.
11
12GLD is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GLD; see the file COPYING. If not, write to
19the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21/*
9d1fe8a4
SC
22This 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"
fb55f9b8 44#include "ldmain.h"
2fa0b342 45
d4e5e3c3
DM
46/* The type of top-level parser input.
47 yylex and yyparse (indirectly) both check this. */
48input_type parser_input;
2fa0b342 49
d4e5e3c3 50/* Radix to use for bfd_scan_vma -- 0 (default to base 10) or 16. */
9d1fe8a4 51int hex_mode;
2e2bf962 52
d4e5e3c3
DM
53/* Line number in the current input file.
54 (FIXME Actually, it doesn't appear to get reset for each file?) */
dc4726c2 55unsigned int lineno = 1;
d4e5e3c3
DM
56
57/* Support for flex reading from more than one input file (stream).
58 `include_stack' is flex's input state for each open file;
59 `file_name_stack' is the file names.
60
61 If `include_stack_ptr' is 0, we haven't started reading anything yet.
62 Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid. */
1d45ccb3 63
9d1fe8a4
SC
64#undef YY_INPUT
65#define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
d4e5e3c3 66
9d1fe8a4 67#define MAX_INCLUDE_DEPTH 10
d4e5e3c3
DM
68static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
69static char *file_name_stack[MAX_INCLUDE_DEPTH];
70static unsigned int include_stack_ptr = 0;
2fa0b342 71
fcf276c4 72static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string,
d4e5e3c3 73 size_t size));
fcf276c4 74static void yy_input PARAMS ((char *, int *result, int max_size));
d4e5e3c3 75
fcf276c4 76static void comment PARAMS ((void));
fb55f9b8 77static void lex_warn_invalid PARAMS ((char *where, char *what));
2fa0b342 78
3d2b83ea 79/* STATES
fb55f9b8
DM
80 EXPRESSION definitely in an expression
81 SCRIPT definitely in a script
82 BOTH either EXPRESSION or SCRIPT
83 DEFSYMEXP in an argument to -defsym
3d2b83ea 84 MRI in an MRI script
9d1fe8a4 85*/
2fa0b342 86#define RTOKEN(x) { yylval.token = x; return x; }
d4e5e3c3
DM
87
88/* Some versions of flex want this. */
89#ifndef yywrap
90int yywrap () { return 1; }
91#endif
9d1fe8a4 92%}
2fa0b342 93
9d1fe8a4
SC
94%a 4000
95%o 5000
ee0c4cf7 96
6bf2e3a7
SC
97CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
98CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
99FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
0d3e45ea 100SYMBOLCHARN [_a-zA-Z\/\.\\0-9]
6bf2e3a7 101FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
9d1fe8a4 102FILENAME {FILENAMECHAR}+
31ddb156 103WHITE [ \t\n\r]+
2fa0b342 104
85e38cfa
SC
105NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
106
107
91e25b4f
PB
108%s SCRIPT
109%s EXPRESSION
91e25b4f
PB
110%s BOTH
111%s DEFSYMEXP
112%s MRI
9d1fe8a4 113%%
91e25b4f 114
d4e5e3c3
DM
115 if (parser_input != input_selected)
116 {
117 /* The first token of the input determines the initial parser state. */
118 input_type t = parser_input;
119 parser_input = input_selected;
31ddb156
ILT
120 switch (t)
121 {
122 case input_script: return INPUT_SCRIPT; break;
123 case input_mri_script: return INPUT_MRI_SCRIPT; break;
124 case input_defsym: return INPUT_DEFSYM; break;
125 default: abort ();
126 }
d4e5e3c3 127 }
6bf2e3a7 128
d4e5e3c3 129<BOTH,SCRIPT,EXPRESSION>"/*" { comment(); }
6bf2e3a7
SC
130
131
0d3e45ea
SC
132<DEFSYMEXP>"-" { RTOKEN('-');}
133<DEFSYMEXP>"+" { RTOKEN('+');}
134<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; }
0d3e45ea 135<DEFSYMEXP>"=" { RTOKEN('='); }
2a28d8b0 136
3d2b83ea 137<MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
f651733a 138 yylval.integer = bfd_scan_vma (yytext+1, 0,16);
3d2b83ea
SC
139 return INT;
140 }
141
91e25b4f 142<MRI,EXPRESSION>([0-9A-Fa-f])+(H|X|B|O|D) {
9f629407 143 int ibase ;
3d2b83ea
SC
144 switch (yytext[yyleng-1]) {
145 case 'X':
146 case 'H':
9f629407 147 ibase = 16;
3d2b83ea
SC
148 break;
149 case 'O':
9f629407 150 ibase = 8;
3d2b83ea
SC
151 break;
152 case 'B':
9f629407 153 ibase = 2;
3d2b83ea
SC
154 break;
155 default:
9f629407 156 ibase = 10;
3d2b83ea 157 }
f651733a 158 yylval.integer = bfd_scan_vma (yytext+1, 0,
9f629407 159 ibase);
3d2b83ea
SC
160 return INT;
161 }
9fce28ed 162<SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? {
f651733a
ILT
163 yylval.integer = bfd_scan_vma (yytext, 0,
164 hex_mode);
9d1fe8a4
SC
165 if (yytext[yyleng-1]=='M'
166 || yytext[yyleng-1] == 'm') {
167 yylval.integer *= 1024*1024;
168 }
169 if (yytext[yyleng-1]=='K'
170 || yytext[yyleng-1]=='k') {
171 yylval.integer *= 1024;
172 }
173 return INT;
174 }
175<BOTH,SCRIPT,EXPRESSION>"]" { RTOKEN(']');}
176<BOTH,SCRIPT,EXPRESSION>"[" { RTOKEN('[');}
177<BOTH,SCRIPT,EXPRESSION>"<<=" { RTOKEN(LSHIFTEQ);}
178<BOTH,SCRIPT,EXPRESSION>">>=" { RTOKEN(RSHIFTEQ);}
179<BOTH,SCRIPT,EXPRESSION>"||" { RTOKEN(OROR);}
180<BOTH,SCRIPT,EXPRESSION>"==" { RTOKEN(EQ);}
181<BOTH,SCRIPT,EXPRESSION>"!=" { RTOKEN(NE);}
182<BOTH,SCRIPT,EXPRESSION>">=" { RTOKEN(GE);}
183<BOTH,SCRIPT,EXPRESSION>"<=" { RTOKEN(LE);}
184<BOTH,SCRIPT,EXPRESSION>"<<" { RTOKEN(LSHIFT);}
185<BOTH,SCRIPT,EXPRESSION>">>" { RTOKEN(RSHIFT);}
186<BOTH,SCRIPT,EXPRESSION>"+=" { RTOKEN(PLUSEQ);}
187<BOTH,SCRIPT,EXPRESSION>"-=" { RTOKEN(MINUSEQ);}
188<BOTH,SCRIPT,EXPRESSION>"*=" { RTOKEN(MULTEQ);}
189<BOTH,SCRIPT,EXPRESSION>"/=" { RTOKEN(DIVEQ);}
190<BOTH,SCRIPT,EXPRESSION>"&=" { RTOKEN(ANDEQ);}
191<BOTH,SCRIPT,EXPRESSION>"|=" { RTOKEN(OREQ);}
192<BOTH,SCRIPT,EXPRESSION>"&&" { RTOKEN(ANDAND);}
193<BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');}
3d2b83ea 194<MRI,BOTH,SCRIPT,EXPRESSION>"," { RTOKEN(',');}
9d1fe8a4
SC
195<BOTH,SCRIPT,EXPRESSION>"&" { RTOKEN('&');}
196<BOTH,SCRIPT,EXPRESSION>"|" { RTOKEN('|');}
197<BOTH,SCRIPT,EXPRESSION>"~" { RTOKEN('~');}
198<BOTH,SCRIPT,EXPRESSION>"!" { RTOKEN('!');}
199<BOTH,SCRIPT,EXPRESSION>"?" { RTOKEN('?');}
200<BOTH,SCRIPT,EXPRESSION>"*" { RTOKEN('*');}
201<BOTH,SCRIPT,EXPRESSION>"+" { RTOKEN('+');}
202<BOTH,SCRIPT,EXPRESSION>"-" { RTOKEN('-');}
203<BOTH,SCRIPT,EXPRESSION>"/" { RTOKEN('/');}
204<BOTH,SCRIPT,EXPRESSION>"%" { RTOKEN('%');}
205<BOTH,SCRIPT,EXPRESSION>"<" { RTOKEN('<');}
3d2b83ea 206<MRI,BOTH,SCRIPT,EXPRESSION>"=" { RTOKEN('=');}
9d1fe8a4
SC
207<BOTH,SCRIPT,EXPRESSION>"}" { RTOKEN('}') ; }
208<BOTH,SCRIPT,EXPRESSION>"{" { RTOKEN('{'); }
209<BOTH,SCRIPT,EXPRESSION>")" { RTOKEN(')');}
210<BOTH,SCRIPT,EXPRESSION>"(" { RTOKEN('(');}
9d1fe8a4
SC
211<BOTH,SCRIPT,EXPRESSION>":" { RTOKEN(':'); }
212<BOTH,SCRIPT,EXPRESSION>";" { RTOKEN(';');}
9d1fe8a4
SC
213<BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
214<BOTH,SCRIPT>"ORIGIN" { RTOKEN(ORIGIN);}
215<BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);}
216<BOTH,SCRIPT>"LENGTH" { RTOKEN(LENGTH);}
217<EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);}
218<EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
219<BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);}
220<EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);}
221<EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
222<EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
223<BOTH,SCRIPT>"MAP" { RTOKEN(MAP);}
224<EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);}
225<BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
226<BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
227<BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
228<BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
dadd414a 229<EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
9d1fe8a4
SC
230<BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
231<BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
232<BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
233<BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
234<BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
235<BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
236<BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
237<BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);}
238<BOTH,SCRIPT>"HLL" { RTOKEN(HLL);}
239<BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
240<BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);}
c477527c 241<BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);}
9d1fe8a4
SC
242<BOTH,SCRIPT>"LONG" { RTOKEN( LONG);}
243<BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);}
244<BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);}
245<BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
dadd414a 246<EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
9d1fe8a4
SC
247<BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
248<BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
249<BOTH,SCRIPT>"INFO" { RTOKEN(INFO);}
250<BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);}
251<BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);}
252<BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
253<BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
254<BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
dadd414a 255<BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);}
9fce28ed 256<EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);}
31ddb156 257<BOTH,SCRIPT>"PROVIDE" { RTOKEN(PROVIDE); }
2e38b71d 258<MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
31ddb156 259<MRI>"\r" { ++ lineno; RTOKEN(NEWLINE); }
91e25b4f 260<MRI>"*".* { /* Mri comment line */ }
2e38b71d 261<MRI>"END" { RTOKEN(ENDWORD); }
85e38cfa
SC
262<MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
263<MRI>"ALIGN" { RTOKEN(ALIGN_K);}
264
3d2b83ea 265<MRI>"CHIP" { RTOKEN(CHIP); }
91e25b4f
PB
266<MRI>"BASE" { RTOKEN(BASE); }
267<MRI>"ALIAS" { RTOKEN(ALIAS); }
85e38cfa 268<MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
3d2b83ea 269<MRI>"LOAD" { RTOKEN(LOAD); }
91e25b4f 270<MRI>"PUBLIC" { RTOKEN(PUBLIC); }
2e38b71d
SC
271<MRI>"ORDER" { RTOKEN(ORDER); }
272<MRI>"NAME" { RTOKEN(NAMEWORD); }
273<MRI>"FORMAT" { RTOKEN(FORMAT); }
274<MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
3d2b83ea 275<MRI>"SECT" { RTOKEN(SECT); }
6bf2e3a7 276<EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
1bd1fa2d
SC
277<MRI>"end" { RTOKEN(ENDWORD); }
278<MRI>"chip" { RTOKEN(CHIP); }
279<MRI>"load" { RTOKEN(LOAD); }
280<MRI>"order" { RTOKEN(ORDER); }
281<MRI>"name" { RTOKEN(NAMEWORD); }
282<MRI>"format" { RTOKEN(FORMAT); }
283<MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
284<MRI>"sect" { RTOKEN(SECT); }
6bf2e3a7 285<EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
3d2b83ea 286
85e38cfa
SC
287<MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
288/* Filename without commas, needed to parse mri stuff */
289 yylval.name = buystring(yytext);
290 return NAME;
291 }
292
293
294<BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
9d1fe8a4
SC
295 yylval.name = buystring(yytext);
296 return NAME;
297 }
d4e5e3c3 298<SCRIPT>{FILENAMECHAR}* { yylval.name = buystring(yytext);
9d1fe8a4
SC
299 return NAME;
300 }
301
d4e5e3c3 302<EXPRESSION,BOTH,SCRIPT>"\""[^\"]*"\"" {
9d1fe8a4
SC
303 /* No matter the state, quotes
304 give what's inside */
305 yylval.name = buystring(yytext+1);
306 yylval.name[yyleng-2] = 0;
307 return NAME;
308 }
309<BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
31ddb156 310<BOTH,SCRIPT,EXPRESSION>"\r" { lineno++;}
d4e5e3c3 311<MRI,BOTH,SCRIPT,EXPRESSION>[ \t]
9d1fe8a4 312
9d1fe8a4 313<<EOF>> {
dadd414a 314 include_stack_ptr--;
9d1fe8a4 315
dadd414a
SC
316 if (include_stack_ptr == 0)
317 {
318 yyterminate();
319 }
320 else
321 {
322 yy_switch_to_buffer(include_stack[include_stack_ptr]);
323
324 }
d4e5e3c3
DM
325 BEGIN(SCRIPT);
326 ldfile_input_filename = file_name_stack[include_stack_ptr-1];
dadd414a
SC
327
328 return END;
329}
fb55f9b8 330
fb55f9b8
DM
331<SCRIPT,MRI>. lex_warn_invalid(" in script", yytext);
332<EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid(" in expression", yytext);
9d1fe8a4 333
9d1fe8a4 334%%
d4e5e3c3
DM
335\f
336
337/* Switch flex to reading script file NAME, open on FILE,
338 saving the current input info on the include stack. */
2fa0b342
DHW
339
340void
8ddef552
DM
341lex_push_file (file, name)
342 FILE *file;
343 char *name;
2fa0b342 344{
9d1fe8a4 345 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
d4e5e3c3
DM
346 {
347 einfo("%F:includes nested too deeply\n");
348 }
dadd414a
SC
349 file_name_stack[include_stack_ptr] = name;
350 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
351
352 include_stack_ptr++;
9d1fe8a4
SC
353 yyin = file;
354 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
d4e5e3c3 355 BEGIN (SCRIPT);
2fa0b342
DHW
356}
357
d4e5e3c3
DM
358/* Return a newly created flex input buffer containing STRING,
359 which is SIZE bytes long. */
360
fcf276c4 361static YY_BUFFER_STATE
d4e5e3c3 362yy_create_string_buffer (string, size)
8ddef552 363 CONST char *string;
d4e5e3c3 364 size_t size;
2fa0b342 365{
9d1fe8a4 366 YY_BUFFER_STATE b;
2fa0b342 367
d4e5e3c3
DM
368 /* Calls to m-alloc get turned by sed into xm-alloc. */
369 b = (YY_BUFFER_STATE) malloc (sizeof (struct yy_buffer_state));
9d1fe8a4 370 b->yy_input_file = 0;
9d1fe8a4 371 b->yy_buf_size = size;
2fa0b342 372
9d1fe8a4 373 /* yy_ch_buf has to be 2 characters longer than the size given because
d4e5e3c3
DM
374 we need to put in 2 end-of-buffer characters. */
375 b->yy_ch_buf = (YY_CHAR *) malloc ((unsigned) (b->yy_buf_size + 3));
2fa0b342 376
9d1fe8a4 377 b->yy_ch_buf[0] = '\n';
d4e5e3c3 378 strcpy (b->yy_ch_buf+1, string);
9d1fe8a4
SC
379 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
380 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
d4e5e3c3 381 b->yy_n_chars = size+1;
9d1fe8a4 382 b->yy_buf_pos = &b->yy_ch_buf[1];
9d1fe8a4 383 b->yy_eof_status = EOF_NOT_SEEN;
2fa0b342 384
d4e5e3c3 385 return b;
2fa0b342 386}
2fa0b342 387
d4e5e3c3
DM
388/* Switch flex to reading from STRING, saving the current input info
389 on the include stack. */
1418c83b 390
9d1fe8a4 391void
8ddef552 392lex_redirect (string)
d4e5e3c3 393 CONST char *string;
9d1fe8a4
SC
394{
395 YY_BUFFER_STATE tmp;
1d45ccb3 396
d4e5e3c3 397 yy_init = 0;
9d1fe8a4 398 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
d4e5e3c3
DM
399 {
400 einfo("%F: macros nested too deeply\n");
401 }
dadd414a
SC
402 file_name_stack[include_stack_ptr] = "redirect";
403 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
404 include_stack_ptr++;
d4e5e3c3
DM
405 tmp = yy_create_string_buffer (string, strlen (string));
406 yy_switch_to_buffer (tmp);
407 BEGIN (SCRIPT);
9d1fe8a4 408}
d4e5e3c3
DM
409\f
410/* Functions to switch to a different flex start condition,
411 saving the current start condition on `state_stack'. */
1d45ccb3 412
d4e5e3c3
DM
413static int state_stack[MAX_INCLUDE_DEPTH * 2];
414static int *state_stack_p = state_stack;
1d45ccb3 415
9d1fe8a4 416void
8ddef552 417ldlex_script ()
9d1fe8a4 418{
dadd414a 419 *(state_stack_p)++ = yy_start;
d4e5e3c3 420 BEGIN (SCRIPT);
9d1fe8a4 421}
1418c83b 422
3d2b83ea 423void
8ddef552 424ldlex_mri_script ()
3d2b83ea 425{
dadd414a 426 *(state_stack_p)++ = yy_start;
d4e5e3c3 427 BEGIN (MRI);
0d3e45ea
SC
428}
429
430void
8ddef552 431ldlex_defsym ()
0d3e45ea 432{
dadd414a 433 *(state_stack_p)++ = yy_start;
d4e5e3c3 434 BEGIN (DEFSYMEXP);
3d2b83ea
SC
435}
436
9d1fe8a4 437void
8ddef552 438ldlex_expression ()
9d1fe8a4 439{
dadd414a 440 *(state_stack_p)++ = yy_start;
d4e5e3c3 441 BEGIN (EXPRESSION);
9d1fe8a4 442}
d4e5e3c3 443
9d1fe8a4 444void
8ddef552 445ldlex_both ()
9d1fe8a4 446{
dadd414a 447 *(state_stack_p)++ = yy_start;
d4e5e3c3 448 BEGIN (BOTH);
2fa0b342
DHW
449}
450
9d1fe8a4 451void
8ddef552 452ldlex_popstate ()
9d1fe8a4 453{
dadd414a 454 yy_start = *(--state_stack_p);
9d1fe8a4 455}
d4e5e3c3
DM
456\f
457
458/* Place up to MAX_SIZE characters in BUF and return in *RESULT
459 either the number of characters read, or 0 to indicate EOF. */
2fa0b342 460
fcf276c4 461static void
d4e5e3c3
DM
462yy_input (buf, result, max_size)
463 char *buf;
464 int *result;
465 int max_size;
9d1fe8a4
SC
466{
467 *result = 0;
468 if (yy_current_buffer->yy_input_file)
d4e5e3c3
DM
469 {
470 if (yyin)
471 {
472 *result = read (fileno (yyin), (char *) buf, max_size);
473 if (*result < 0)
474 einfo ("%F%P: read in flex scanner failed");
475 }
476 }
9d1fe8a4 477}
6bf2e3a7 478
d4e5e3c3
DM
479/* Eat the rest of a C-style comment. */
480
fcf276c4
ILT
481static void
482comment ()
85e38cfa
SC
483{
484 int c;
d4e5e3c3 485
85e38cfa
SC
486 while (1)
487 {
488 c = input();
d4e5e3c3 489 while (c != '*' && c != EOF)
85e38cfa 490 {
31ddb156 491 if (c == '\n' || c == '\r')
d4e5e3c3 492 lineno++;
85e38cfa
SC
493 c = input();
494 }
495
85e38cfa
SC
496 if (c == '*')
497 {
498 c = input();
d4e5e3c3 499 while (c == '*')
85e38cfa 500 c = input();
d4e5e3c3 501 if (c == '/')
85e38cfa
SC
502 break; /* found the end */
503 }
504
31ddb156 505 if (c == '\n' || c == '\r')
d4e5e3c3
DM
506 lineno++;
507
508 if (c == EOF)
85e38cfa 509 {
d4e5e3c3 510 einfo( "%F%P: EOF in comment\n");
85e38cfa
SC
511 break;
512 }
513 }
514}
fb55f9b8 515
d4e5e3c3
DM
516/* Warn the user about a garbage character WHAT in the input
517 in context WHERE. */
518
fb55f9b8
DM
519static void
520lex_warn_invalid (where, what)
521 char *where, *what;
522{
523 fprintf(stderr,
524 "%s: ignoring invalid character `%s'%s\n",
525 program_name, what, where);
526}
This page took 0.190139 seconds and 4 git commands to generate.