Initialize Tizen 2.3
[external/binutils.git] / ld / ldlex.l
1 %option nounput
2
3 %{
4
5 /* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
6    2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
7    Free Software Foundation, Inc.
8    Written by Steve Chamberlain of Cygnus Support.
9
10    This file is part of the GNU Binutils.
11
12    This program is free software; you can redistribute it and/or modify
13    it under the terms of the GNU General Public License as published by
14    the Free Software Foundation; either version 3 of the License, or
15    (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
25    MA 02110-1301, USA.  */
26
27 #include "bfd.h"
28 #include "safe-ctype.h"
29 #include "bfdlink.h"
30 #include "ld.h"
31 #include "ldmisc.h"
32 #include "ldexp.h"
33 #include "ldlang.h"
34 #include <ldgram.h>
35 #include "ldfile.h"
36 #include "ldlex.h"
37 #include "ldmain.h"
38 #include "libiberty.h"
39
40 /* The type of top-level parser input.
41    yylex and yyparse (indirectly) both check this.  */
42 input_type parser_input;
43
44 /* Line number in the current input file.
45    (FIXME Actually, it doesn't appear to get reset for each file?)  */
46 unsigned int lineno = 1;
47
48 /* The string we are currently lexing, or NULL if we are reading a
49    file.  */
50 const char *lex_string = NULL;
51
52 /* Support for flex reading from more than one input file (stream).
53    `include_stack' is flex's input state for each open file;
54    `file_name_stack' is the file names.  `lineno_stack' is the current
55    line numbers.
56
57    If `include_stack_ptr' is 0, we haven't started reading anything yet.
58    Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid.  */
59
60 #undef YY_INPUT
61 #define YY_INPUT(buf,result,max_size) result = yy_input (buf, max_size)
62
63 #ifndef YY_NO_UNPUT
64 #define YY_NO_UNPUT
65 #endif
66
67 #define MAX_INCLUDE_DEPTH 10
68 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
69 static const char *file_name_stack[MAX_INCLUDE_DEPTH];
70 static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
71 static unsigned int include_stack_ptr = 0;
72 static int vers_node_nesting = 0;
73
74 static int yy_input (char *, int);
75 static void comment (void);
76 static void lex_warn_invalid (char *where, char *what);
77
78 /* STATES
79         EXPRESSION      definitely in an expression
80         SCRIPT          definitely in a script
81         BOTH            either EXPRESSION or SCRIPT
82         DEFSYMEXP       in an argument to -defsym
83         MRI             in an MRI script
84         VERS_START      starting a Sun style mapfile
85         VERS_SCRIPT     a Sun style mapfile
86         VERS_NODE       a node within a Sun style mapfile
87 */
88 #define RTOKEN(x)  {  yylval.token = x; return x; }
89
90 /* Some versions of flex want this.  */
91 #ifndef yywrap
92 int yywrap (void) { return 1; }
93 #endif
94 %}
95
96 %a 4000
97 %o 5000
98
99 CMDFILENAMECHAR   [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
100 CMDFILENAMECHAR1  [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
101 FILENAMECHAR1   [_a-zA-Z\/\.\\\$\_\~]
102 SYMBOLCHARN     [_a-zA-Z\/\.\\\$\_\~0-9]
103 FILENAMECHAR    [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
104 WILDCHAR        [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*\^\!]
105 WHITE           [ \t\n\r]+
106
107 NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
108
109 V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
110 V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
111
112 %s SCRIPT
113 %s EXPRESSION
114 %s BOTH
115 %s DEFSYMEXP
116 %s MRI
117 %s VERS_START
118 %s VERS_SCRIPT
119 %s VERS_NODE
120 %%
121
122   if (parser_input != input_selected)
123     {
124       /* The first token of the input determines the initial parser state.  */
125       input_type t = parser_input;
126       parser_input = input_selected;
127       switch (t)
128         {
129         case input_script: return INPUT_SCRIPT; break;
130         case input_mri_script: return INPUT_MRI_SCRIPT; break;
131         case input_version_script: return INPUT_VERSION_SCRIPT; break;
132         case input_dynamic_list: return INPUT_DYNAMIC_LIST; break;
133         case input_defsym: return INPUT_DEFSYM; break;
134         default: abort ();
135         }
136     }
137
138 <BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT>"/*"   { comment (); }
139
140
141 <DEFSYMEXP>"-"                  { RTOKEN('-');}
142 <DEFSYMEXP>"+"                  { RTOKEN('+');}
143 <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}*   { yylval.name = xstrdup (yytext); return NAME; }
144 <DEFSYMEXP>"="                  { RTOKEN('='); }
145
146 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
147                                 yylval.integer = bfd_scan_vma (yytext + 1, 0, 16);
148                                 yylval.bigint.str = NULL;
149                                 return INT;
150                         }
151
152 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
153                                    int ibase ;
154                                    switch (yytext[yyleng - 1]) {
155                                     case 'X':
156                                     case 'x':
157                                     case 'H':
158                                     case 'h':
159                                      ibase = 16;
160                                      break;
161                                     case 'O':
162                                     case 'o':
163                                      ibase = 8;
164                                      break;
165                                     case 'B':
166                                     case 'b':
167                                      ibase = 2;
168                                      break;
169                                     default:
170                                      ibase = 10;
171                                    }
172                                    yylval.integer = bfd_scan_vma (yytext, 0,
173                                                                   ibase);
174                                    yylval.bigint.str = NULL;
175                                    return INT;
176                                  }
177 <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
178                                   char *s = yytext;
179                                   int ibase = 0;
180
181                                   if (*s == '$')
182                                     {
183                                       ++s;
184                                       ibase = 16;
185                                     }
186                                   yylval.integer = bfd_scan_vma (s, 0, ibase);
187                                   yylval.bigint.str = NULL;
188                                   if (yytext[yyleng - 1] == 'M'
189                                       || yytext[yyleng - 1] == 'm')
190                                     {
191                                       yylval.integer *= 1024 * 1024;
192                                     }
193                                   else if (yytext[yyleng - 1] == 'K'
194                                       || yytext[yyleng - 1]=='k')
195                                     {
196                                       yylval.integer *= 1024;
197                                     }
198                                   else if (yytext[0] == '0'
199                                            && (yytext[1] == 'x'
200                                                || yytext[1] == 'X'))
201                                     {
202                                       yylval.bigint.str = xstrdup (yytext + 2);
203                                     }
204                                   return INT;
205                                 }
206 <BOTH,SCRIPT,EXPRESSION,MRI>"]"         { RTOKEN(']');}
207 <BOTH,SCRIPT,EXPRESSION,MRI>"["         { RTOKEN('[');}
208 <BOTH,SCRIPT,EXPRESSION,MRI>"<<="       { RTOKEN(LSHIFTEQ);}
209 <BOTH,SCRIPT,EXPRESSION,MRI>">>="       { RTOKEN(RSHIFTEQ);}
210 <BOTH,SCRIPT,EXPRESSION,MRI>"||"        { RTOKEN(OROR);}
211 <BOTH,SCRIPT,EXPRESSION,MRI>"=="        { RTOKEN(EQ);}
212 <BOTH,SCRIPT,EXPRESSION,MRI>"!="        { RTOKEN(NE);}
213 <BOTH,SCRIPT,EXPRESSION,MRI>">="        { RTOKEN(GE);}
214 <BOTH,SCRIPT,EXPRESSION,MRI>"<="        { RTOKEN(LE);}
215 <BOTH,SCRIPT,EXPRESSION,MRI>"<<"        { RTOKEN(LSHIFT);}
216 <BOTH,SCRIPT,EXPRESSION,MRI>">>"        { RTOKEN(RSHIFT);}
217 <BOTH,SCRIPT,EXPRESSION,MRI>"+="        { RTOKEN(PLUSEQ);}
218 <BOTH,SCRIPT,EXPRESSION,MRI>"-="        { RTOKEN(MINUSEQ);}
219 <BOTH,SCRIPT,EXPRESSION,MRI>"*="        { RTOKEN(MULTEQ);}
220 <BOTH,SCRIPT,EXPRESSION,MRI>"/="        { RTOKEN(DIVEQ);}
221 <BOTH,SCRIPT,EXPRESSION,MRI>"&="        { RTOKEN(ANDEQ);}
222 <BOTH,SCRIPT,EXPRESSION,MRI>"|="        { RTOKEN(OREQ);}
223 <BOTH,SCRIPT,EXPRESSION,MRI>"&&"        { RTOKEN(ANDAND);}
224 <BOTH,SCRIPT,EXPRESSION,MRI>">"         { RTOKEN('>');}
225 <BOTH,SCRIPT,EXPRESSION,MRI>","         { RTOKEN(',');}
226 <BOTH,SCRIPT,EXPRESSION,MRI>"&"         { RTOKEN('&');}
227 <BOTH,SCRIPT,EXPRESSION,MRI>"|"         { RTOKEN('|');}
228 <BOTH,SCRIPT,EXPRESSION,MRI>"~"         { RTOKEN('~');}
229 <BOTH,SCRIPT,EXPRESSION,MRI>"!"         { RTOKEN('!');}
230 <BOTH,SCRIPT,EXPRESSION,MRI>"?"         { RTOKEN('?');}
231 <BOTH,SCRIPT,EXPRESSION,MRI>"*"         { RTOKEN('*');}
232 <BOTH,SCRIPT,EXPRESSION,MRI>"+"         { RTOKEN('+');}
233 <BOTH,SCRIPT,EXPRESSION,MRI>"-"         { RTOKEN('-');}
234 <BOTH,SCRIPT,EXPRESSION,MRI>"/"         { RTOKEN('/');}
235 <BOTH,SCRIPT,EXPRESSION,MRI>"%"         { RTOKEN('%');}
236 <BOTH,SCRIPT,EXPRESSION,MRI>"<"         { RTOKEN('<');}
237 <BOTH,SCRIPT,EXPRESSION,MRI>"="         { RTOKEN('=');}
238 <BOTH,SCRIPT,EXPRESSION,MRI>"}"         { RTOKEN('}') ; }
239 <BOTH,SCRIPT,EXPRESSION,MRI>"{"         { RTOKEN('{'); }
240 <BOTH,SCRIPT,EXPRESSION,MRI>")"         { RTOKEN(')');}
241 <BOTH,SCRIPT,EXPRESSION,MRI>"("         { RTOKEN('(');}
242 <BOTH,SCRIPT,EXPRESSION,MRI>":"         { RTOKEN(':'); }
243 <BOTH,SCRIPT,EXPRESSION,MRI>";"         { RTOKEN(';');}
244 <BOTH,SCRIPT>"MEMORY"                   { RTOKEN(MEMORY);}
245 <BOTH,SCRIPT>"REGION_ALIAS"             { RTOKEN(REGION_ALIAS);}
246 <BOTH,SCRIPT>"LD_FEATURE"               { RTOKEN(LD_FEATURE);}
247 <BOTH,SCRIPT,EXPRESSION>"ORIGIN"        { RTOKEN(ORIGIN);}
248 <BOTH,SCRIPT>"VERSION"                  { RTOKEN(VERSIONK);}
249 <EXPRESSION,BOTH,SCRIPT>"BLOCK"         { RTOKEN(BLOCK);}
250 <EXPRESSION,BOTH,SCRIPT>"BIND"          { RTOKEN(BIND);}
251 <BOTH,SCRIPT,EXPRESSION>"LENGTH"        { RTOKEN(LENGTH);}
252 <EXPRESSION,BOTH,SCRIPT>"ALIGN"         { RTOKEN(ALIGN_K);}
253 <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_ALIGN"    { RTOKEN(DATA_SEGMENT_ALIGN);}
254 <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_RELRO_END"        { RTOKEN(DATA_SEGMENT_RELRO_END);}
255 <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_END"      { RTOKEN(DATA_SEGMENT_END);}
256 <EXPRESSION,BOTH,SCRIPT>"ADDR"          { RTOKEN(ADDR);}
257 <EXPRESSION,BOTH,SCRIPT>"LOADADDR"      { RTOKEN(LOADADDR);}
258 <EXPRESSION,BOTH,SCRIPT>"ALIGNOF"       { RTOKEN(ALIGNOF); }
259 <EXPRESSION,BOTH>"MAX"                  { RTOKEN(MAX_K); }
260 <EXPRESSION,BOTH>"MIN"                  { RTOKEN(MIN_K); }
261 <EXPRESSION,BOTH,SCRIPT>"ASSERT"        { RTOKEN(ASSERT_K); }
262 <BOTH,SCRIPT>"ENTRY"                    { RTOKEN(ENTRY);}
263 <BOTH,SCRIPT,MRI>"EXTERN"               { RTOKEN(EXTERN);}
264 <EXPRESSION,BOTH,SCRIPT>"NEXT"          { RTOKEN(NEXT);}
265 <EXPRESSION,BOTH,SCRIPT>"sizeof_headers"        { RTOKEN(SIZEOF_HEADERS);}
266 <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS"        { RTOKEN(SIZEOF_HEADERS);}
267 <EXPRESSION,BOTH,SCRIPT>"SEGMENT_START" { RTOKEN(SEGMENT_START);}
268 <BOTH,SCRIPT>"MAP"                      { RTOKEN(MAP);}
269 <EXPRESSION,BOTH,SCRIPT>"SIZEOF"        { RTOKEN(SIZEOF);}
270 <BOTH,SCRIPT>"TARGET"                   { RTOKEN(TARGET_K);}
271 <BOTH,SCRIPT>"SEARCH_DIR"               { RTOKEN(SEARCH_DIR);}
272 <BOTH,SCRIPT>"OUTPUT"                   { RTOKEN(OUTPUT);}
273 <BOTH,SCRIPT>"INPUT"                    { RTOKEN(INPUT);}
274 <EXPRESSION,BOTH,SCRIPT>"GROUP"         { RTOKEN(GROUP);}
275 <EXPRESSION,BOTH,SCRIPT>"AS_NEEDED"     { RTOKEN(AS_NEEDED);}
276 <EXPRESSION,BOTH,SCRIPT>"DEFINED"       { RTOKEN(DEFINED);}
277 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS"    { RTOKEN(CREATE_OBJECT_SYMBOLS);}
278 <BOTH,SCRIPT>"CONSTRUCTORS"             { RTOKEN( CONSTRUCTORS);}
279 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION"  { RTOKEN(FORCE_COMMON_ALLOCATION);}
280 <BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
281 <BOTH,SCRIPT>"SECTIONS"                 { RTOKEN(SECTIONS);}
282 <BOTH,SCRIPT>"INSERT"                   { RTOKEN(INSERT_K);}
283 <BOTH,SCRIPT>"AFTER"                    { RTOKEN(AFTER);}
284 <BOTH,SCRIPT>"BEFORE"                   { RTOKEN(BEFORE);}
285 <BOTH,SCRIPT>"FILL"                     { RTOKEN(FILL);}
286 <BOTH,SCRIPT>"STARTUP"                  { RTOKEN(STARTUP);}
287 <BOTH,SCRIPT>"OUTPUT_FORMAT"            { RTOKEN(OUTPUT_FORMAT);}
288 <BOTH,SCRIPT>"OUTPUT_ARCH"              { RTOKEN( OUTPUT_ARCH);}
289 <BOTH,SCRIPT>"HLL"                      { RTOKEN(HLL);}
290 <BOTH,SCRIPT>"SYSLIB"                   { RTOKEN(SYSLIB);}
291 <BOTH,SCRIPT>"FLOAT"                    { RTOKEN(FLOAT);}
292 <BOTH,SCRIPT>"QUAD"                     { RTOKEN( QUAD);}
293 <BOTH,SCRIPT>"SQUAD"                    { RTOKEN( SQUAD);}
294 <BOTH,SCRIPT>"LONG"                     { RTOKEN( LONG);}
295 <BOTH,SCRIPT>"SHORT"                    { RTOKEN( SHORT);}
296 <BOTH,SCRIPT>"BYTE"                     { RTOKEN( BYTE);}
297 <BOTH,SCRIPT>"NOFLOAT"                  { RTOKEN(NOFLOAT);}
298 <EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS"   { RTOKEN(NOCROSSREFS);}
299 <BOTH,SCRIPT>"OVERLAY"                  { RTOKEN(OVERLAY); }
300 <BOTH,SCRIPT>"SORT_BY_NAME"             { RTOKEN(SORT_BY_NAME); }
301 <BOTH,SCRIPT>"SORT_BY_ALIGNMENT"        { RTOKEN(SORT_BY_ALIGNMENT); }
302 <BOTH,SCRIPT>"SORT"                     { RTOKEN(SORT_BY_NAME); }
303 <BOTH,SCRIPT>"SORT_BY_INIT_PRIORITY"    { RTOKEN(SORT_BY_INIT_PRIORITY); }
304 <EXPRESSION,BOTH,SCRIPT>"NOLOAD"        { RTOKEN(NOLOAD);}
305 <EXPRESSION,BOTH,SCRIPT>"DSECT"         { RTOKEN(DSECT);}
306 <EXPRESSION,BOTH,SCRIPT>"COPY"          { RTOKEN(COPY);}
307 <EXPRESSION,BOTH,SCRIPT>"INFO"          { RTOKEN(INFO);}
308 <EXPRESSION,BOTH,SCRIPT>"OVERLAY"       { RTOKEN(OVERLAY);}
309 <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RO"    { RTOKEN(ONLY_IF_RO); }
310 <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RW"    { RTOKEN(ONLY_IF_RW); }
311 <EXPRESSION,BOTH,SCRIPT>"SPECIAL"       { RTOKEN(SPECIAL); }
312 <BOTH,SCRIPT>"o"                        { RTOKEN(ORIGIN);}
313 <BOTH,SCRIPT>"org"                      { RTOKEN(ORIGIN);}
314 <BOTH,SCRIPT>"l"                        { RTOKEN( LENGTH);}
315 <BOTH,SCRIPT>"len"                      { RTOKEN( LENGTH);}
316 <EXPRESSION,BOTH,SCRIPT>"INPUT_SECTION_FLAGS"   { RTOKEN(INPUT_SECTION_FLAGS); }
317 <EXPRESSION,BOTH,SCRIPT>"INCLUDE"       { RTOKEN(INCLUDE);}
318 <BOTH,SCRIPT>"PHDRS"                    { RTOKEN (PHDRS); }
319 <EXPRESSION,BOTH,SCRIPT>"AT"            { RTOKEN(AT);}
320 <EXPRESSION,BOTH,SCRIPT>"SUBALIGN"      { RTOKEN(SUBALIGN);}
321 <EXPRESSION,BOTH,SCRIPT>"PROVIDE"       { RTOKEN(PROVIDE); }
322 <EXPRESSION,BOTH,SCRIPT>"PROVIDE_HIDDEN" { RTOKEN(PROVIDE_HIDDEN); }
323 <EXPRESSION,BOTH,SCRIPT>"KEEP"          { RTOKEN(KEEP); }
324 <EXPRESSION,BOTH,SCRIPT>"EXCLUDE_FILE"  { RTOKEN(EXCLUDE_FILE); }
325 <EXPRESSION,BOTH,SCRIPT>"CONSTANT"      { RTOKEN(CONSTANT);}
326 <MRI>"#".*\n?                   { ++ lineno; }
327 <MRI>"\n"                       { ++ lineno;  RTOKEN(NEWLINE); }
328 <MRI>"*".*                      { /* Mri comment line */ }
329 <MRI>";".*                      { /* Mri comment line */ }
330 <MRI>"END"                      { RTOKEN(ENDWORD); }
331 <MRI>"ALIGNMOD"                 { RTOKEN(ALIGNMOD);}
332 <MRI>"ALIGN"                    { RTOKEN(ALIGN_K);}
333 <MRI>"CHIP"                     { RTOKEN(CHIP); }
334 <MRI>"BASE"                     { RTOKEN(BASE); }
335 <MRI>"ALIAS"                    { RTOKEN(ALIAS); }
336 <MRI>"TRUNCATE"                 { RTOKEN(TRUNCATE); }
337 <MRI>"LOAD"                     { RTOKEN(LOAD); }
338 <MRI>"PUBLIC"                   { RTOKEN(PUBLIC); }
339 <MRI>"ORDER"                    { RTOKEN(ORDER); }
340 <MRI>"NAME"                     { RTOKEN(NAMEWORD); }
341 <MRI>"FORMAT"                   { RTOKEN(FORMAT); }
342 <MRI>"CASE"                     { RTOKEN(CASE); }
343 <MRI>"START"                    { RTOKEN(START); }
344 <MRI>"LIST".*                   { RTOKEN(LIST); /* LIST and ignore to end of line */ }
345 <MRI>"SECT"                     { RTOKEN(SECT); }
346 <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE"                  { RTOKEN(ABSOLUTE); }
347 <MRI>"end"                      { RTOKEN(ENDWORD); }
348 <MRI>"alignmod"                 { RTOKEN(ALIGNMOD);}
349 <MRI>"align"                    { RTOKEN(ALIGN_K);}
350 <MRI>"chip"                     { RTOKEN(CHIP); }
351 <MRI>"base"                     { RTOKEN(BASE); }
352 <MRI>"alias"                    { RTOKEN(ALIAS); }
353 <MRI>"truncate"                 { RTOKEN(TRUNCATE); }
354 <MRI>"load"                     { RTOKEN(LOAD); }
355 <MRI>"public"                   { RTOKEN(PUBLIC); }
356 <MRI>"order"                    { RTOKEN(ORDER); }
357 <MRI>"name"                     { RTOKEN(NAMEWORD); }
358 <MRI>"format"                   { RTOKEN(FORMAT); }
359 <MRI>"case"                     { RTOKEN(CASE); }
360 <MRI>"extern"                   { RTOKEN(EXTERN); }
361 <MRI>"start"                    { RTOKEN(START); }
362 <MRI>"list".*                   { RTOKEN(LIST); /* LIST and ignore to end of line */ }
363 <MRI>"sect"                     { RTOKEN(SECT); }
364 <EXPRESSION,BOTH,SCRIPT,MRI>"absolute"                  { RTOKEN(ABSOLUTE); }
365
366 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}*  {
367 /* Filename without commas, needed to parse mri stuff */
368                                  yylval.name = xstrdup (yytext);
369                                   return NAME;
370                                 }
371
372
373 <BOTH>{FILENAMECHAR1}{FILENAMECHAR}*    {
374                                  yylval.name = xstrdup (yytext);
375                                   return NAME;
376                                 }
377 <BOTH>"-l"{FILENAMECHAR}+ {
378                                   yylval.name = xstrdup (yytext + 2);
379                                   return LNAME;
380                                 }
381 <EXPRESSION>{FILENAMECHAR1}{NOCFILENAMECHAR}*   {
382                                  yylval.name = xstrdup (yytext);
383                                   return NAME;
384                                 }
385 <EXPRESSION>"-l"{NOCFILENAMECHAR}+ {
386                                   yylval.name = xstrdup (yytext + 2);
387                                   return LNAME;
388                                 }
389 <SCRIPT>{WILDCHAR}* {
390                 /* Annoyingly, this pattern can match comments, and we have
391                    longest match issues to consider.  So if the first two
392                    characters are a comment opening, put the input back and
393                    try again.  */
394                 if (yytext[0] == '/' && yytext[1] == '*')
395                   {
396                     yyless (2);
397                     comment ();
398                   }
399                 else
400                   {
401                     yylval.name = xstrdup (yytext);
402                     return NAME;
403                   }
404         }
405
406 <EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {
407                                         /* No matter the state, quotes
408                                            give what's inside */
409                                         yylval.name = xstrdup (yytext + 1);
410                                         yylval.name[yyleng - 2] = 0;
411                                         return NAME;
412                                 }
413 <BOTH,SCRIPT,EXPRESSION>"\n"            { lineno++;}
414 <MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+    { }
415
416 <VERS_NODE,VERS_SCRIPT>[:,;]    { return *yytext; }
417
418 <VERS_NODE>global               { RTOKEN(GLOBAL); }
419
420 <VERS_NODE>local                { RTOKEN(LOCAL); }
421
422 <VERS_NODE>extern               { RTOKEN(EXTERN); }
423
424 <VERS_NODE>{V_IDENTIFIER}       { yylval.name = xstrdup (yytext);
425                                   return VERS_IDENTIFIER; }
426
427 <VERS_SCRIPT>{V_TAG}            { yylval.name = xstrdup (yytext);
428                                   return VERS_TAG; }
429
430 <VERS_START>"{"                 { BEGIN(VERS_SCRIPT); return *yytext; }
431
432 <VERS_SCRIPT>"{"                { BEGIN(VERS_NODE);
433                                   vers_node_nesting = 0;
434                                   return *yytext;
435                                 }
436 <VERS_SCRIPT>"}"                { return *yytext; }
437 <VERS_NODE>"{"                  { vers_node_nesting++; return *yytext; }
438 <VERS_NODE>"}"                  { if (--vers_node_nesting < 0)
439                                     BEGIN(VERS_SCRIPT);
440                                   return *yytext;
441                                 }
442
443 <VERS_START,VERS_NODE,VERS_SCRIPT>[\n]          { lineno++; }
444
445 <VERS_START,VERS_NODE,VERS_SCRIPT>#.*           { /* Eat up comments */ }
446
447 <VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+      { /* Eat up whitespace */ }
448
449 <<EOF>> {
450   include_stack_ptr--;
451
452   if (include_stack_ptr == 0)
453   {
454     yyterminate ();
455   }
456   else
457   {
458     yy_switch_to_buffer (include_stack[include_stack_ptr]);
459   }
460
461   ldfile_input_filename = file_name_stack[include_stack_ptr - 1];
462   lineno = lineno_stack[include_stack_ptr];
463
464   return END;
465 }
466
467 <SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>.  lex_warn_invalid (" in script", yytext);
468 <EXPRESSION,DEFSYMEXP,BOTH>.    lex_warn_invalid (" in expression", yytext);
469
470 %%
471 \f
472
473 /* Switch flex to reading script file NAME, open on FILE,
474    saving the current input info on the include stack.  */
475
476 void
477 lex_push_file (FILE *file, const char *name)
478 {
479   if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
480     {
481       einfo ("%F:includes nested too deeply\n");
482     }
483   file_name_stack[include_stack_ptr] = name;
484   lineno_stack[include_stack_ptr] = lineno;
485   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
486
487   include_stack_ptr++;
488   lineno = 1;
489   yyin = file;
490   yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
491 }
492
493 /* Return a newly created flex input buffer containing STRING,
494    which is SIZE bytes long.  */
495
496 static YY_BUFFER_STATE
497 yy_create_string_buffer (const char *string, size_t size)
498 {
499   YY_BUFFER_STATE b;
500
501   /* Calls to m-alloc get turned by sed into xm-alloc.  */
502   b = malloc (sizeof (struct yy_buffer_state));
503   b->yy_input_file = 0;
504   b->yy_buf_size = size;
505
506   /* yy_ch_buf has to be 2 characters longer than the size given because
507      we need to put in 2 end-of-buffer characters.  */
508   b->yy_ch_buf = malloc ((unsigned) (b->yy_buf_size + 3));
509
510   b->yy_ch_buf[0] = '\n';
511   strcpy (b->yy_ch_buf+1, string);
512   b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
513   b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
514   b->yy_n_chars = size+1;
515   b->yy_buf_pos = &b->yy_ch_buf[1];
516
517   b->yy_is_our_buffer = 1;
518   b->yy_is_interactive = 0;
519   b->yy_at_bol = 1;
520   b->yy_fill_buffer = 0;
521
522   /* flex 2.4.7 changed the interface.  FIXME: We should not be using
523      a flex internal interface in the first place!  */
524 #ifdef YY_BUFFER_NEW
525   b->yy_buffer_status = YY_BUFFER_NEW;
526 #else
527   b->yy_eof_status = EOF_NOT_SEEN;
528 #endif
529
530   return b;
531 }
532
533 /* Switch flex to reading from STRING, saving the current input info
534    on the include stack.  */
535
536 void
537 lex_redirect (const char *string)
538 {
539   YY_BUFFER_STATE tmp;
540
541   yy_init = 0;
542   if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
543     {
544       einfo("%F: macros nested too deeply\n");
545     }
546   file_name_stack[include_stack_ptr] = "redirect";
547   lineno_stack[include_stack_ptr] = lineno;
548   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
549   include_stack_ptr++;
550   lineno = 1;
551   tmp = yy_create_string_buffer (string, strlen (string));
552   yy_switch_to_buffer (tmp);
553 }
554 \f
555 /* Functions to switch to a different flex start condition,
556    saving the current start condition on `state_stack'.  */
557
558 static int state_stack[MAX_INCLUDE_DEPTH * 2];
559 static int *state_stack_p = state_stack;
560
561 void
562 ldlex_script (void)
563 {
564   *(state_stack_p)++ = yy_start;
565   BEGIN (SCRIPT);
566 }
567
568 void
569 ldlex_mri_script (void)
570 {
571   *(state_stack_p)++ = yy_start;
572   BEGIN (MRI);
573 }
574
575 void
576 ldlex_version_script (void)
577 {
578   *(state_stack_p)++ = yy_start;
579   BEGIN (VERS_START);
580 }
581
582 void
583 ldlex_version_file (void)
584 {
585   *(state_stack_p)++ = yy_start;
586   BEGIN (VERS_SCRIPT);
587 }
588
589 void
590 ldlex_defsym (void)
591 {
592   *(state_stack_p)++ = yy_start;
593   BEGIN (DEFSYMEXP);
594 }
595
596 void
597 ldlex_expression (void)
598 {
599   *(state_stack_p)++ = yy_start;
600   BEGIN (EXPRESSION);
601 }
602
603 void
604 ldlex_both (void)
605 {
606   *(state_stack_p)++ = yy_start;
607   BEGIN (BOTH);
608 }
609
610 void
611 ldlex_popstate (void)
612 {
613   yy_start = *(--state_stack_p);
614 }
615 \f
616
617 /* Place up to MAX_SIZE characters in BUF and return
618    either the number of characters read, or 0 to indicate EOF.  */
619
620 static int
621 yy_input (char *buf, int max_size)
622 {
623   int result = 0;
624   if (YY_CURRENT_BUFFER->yy_input_file)
625     {
626       if (yyin)
627         {
628           result = fread (buf, 1, max_size, yyin);
629           if (result < max_size && ferror (yyin))
630             einfo ("%F%P: read in flex scanner failed\n");
631         }
632     }
633   return result;
634 }
635
636 /* Eat the rest of a C-style comment.  */
637
638 static void
639 comment (void)
640 {
641   int c;
642
643   while (1)
644   {
645     c = input();
646     while (c != '*' && c != EOF)
647     {
648       if (c == '\n')
649         lineno++;
650       c = input();
651     }
652
653     if (c == '*')
654     {
655       c = input();
656       while (c == '*')
657        c = input();
658       if (c == '/')
659        break;                   /* found the end */
660     }
661
662     if (c == '\n')
663       lineno++;
664
665     if (c == EOF)
666     {
667       einfo( "%F%P: EOF in comment\n");
668       break;
669     }
670   }
671 }
672
673 /* Warn the user about a garbage character WHAT in the input
674    in context WHERE.  */
675
676 static void
677 lex_warn_invalid (char *where, char *what)
678 {
679   char buf[5];
680
681   /* If we have found an input file whose format we do not recognize,
682      and we are therefore treating it as a linker script, and we find
683      an invalid character, then most likely this is a real object file
684      of some different format.  Treat it as such.  */
685   if (ldfile_assumed_script)
686     {
687       bfd_set_error (bfd_error_file_not_recognized);
688       einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);
689     }
690
691   if (! ISPRINT (*what))
692     {
693       sprintf (buf, "\\%03o", *(unsigned char *) what);
694       what = buf;
695     }
696
697   einfo ("%P:%S: ignoring invalid character `%s'%s\n", what, where);
698 }