]> git.saurik.com Git - bison.git/blob - src/scan-gram.l
8193ddf2d928eb0a6b9efdc4d96740104d10fb0a
[bison.git] / src / scan-gram.l
1 /* Bison Grammar Scanner -*- C -*-
2
3 Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
4
5 This file is part of Bison, the GNU Compiler Compiler.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program 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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21 */
22
23 %option debug nodefault nounput noyywrap never-interactive
24 %option prefix="gram_" outfile="lex.yy.c"
25
26 %{
27 /* Work around a bug in flex 2.5.31. See Debian bug 333231
28 <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
29 #undef gram_wrap
30 #define gram_wrap() 1
31
32 #define FLEX_PREFIX(Id) gram_ ## Id
33 #include "flex-scanner.h"
34
35 #include "complain.h"
36 #include "files.h"
37 #include "gram.h"
38 #include "quotearg.h"
39 #include "reader.h"
40 #include "uniqstr.h"
41
42 #include <mbswidth.h>
43 #include <quote.h>
44
45 #include "scan-gram.h"
46
47 #define YY_DECL GRAM_LEX_DECL
48
49 #define YY_USER_INIT \
50 code_start = scanner_cursor = loc->start; \
51
52 /* Location of scanner cursor. */
53 static boundary scanner_cursor;
54
55 #define YY_USER_ACTION location_compute (loc, &scanner_cursor, yytext, yyleng);
56
57 static size_t no_cr_read (FILE *, char *, size_t);
58 #define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
59
60 /* A string representing the most recently saved token. */
61 char *last_string;
62
63 void
64 gram_scanner_last_string_free (void)
65 {
66 STRING_FREE;
67 }
68
69 /* The location of the most recently saved token, if it was a
70 BRACED_CODE token; otherwise, this has an unspecified value. */
71 location gram_last_braced_code_loc;
72
73 static void handle_syncline (char *, location);
74 static unsigned long int scan_integer (char const *p, int base, location loc);
75 static int convert_ucn_to_byte (char const *hex_text);
76 static void unexpected_eof (boundary, char const *);
77 static void unexpected_newline (boundary, char const *);
78
79 %}
80 /* A C-like comment in directives/rules. */
81 %x SC_YACC_COMMENT
82 /* Strings and characters in directives/rules. */
83 %x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
84 /* A identifier was just read in directives/rules. Special state
85 to capture the sequence `identifier :'. */
86 %x SC_AFTER_IDENTIFIER
87
88 /* Three types of user code:
89 - prologue (code between `%{' `%}' in the first section, before %%);
90 - actions, printers, union, etc, (between braced in the middle section);
91 - epilogue (everything after the second %%). */
92 %x SC_PROLOGUE SC_BRACED_CODE SC_EPILOGUE
93 /* C and C++ comments in code. */
94 %x SC_COMMENT SC_LINE_COMMENT
95 /* Strings and characters in code. */
96 %x SC_STRING SC_CHARACTER
97
98 letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
99 id {letter}({letter}|[0-9])*
100 directive %{letter}({letter}|[0-9]|-)*
101 int [0-9]+
102
103 /* POSIX says that a tag must be both an id and a C union member, but
104 historically almost any character is allowed in a tag. We disallow
105 NUL and newline, as this simplifies our implementation. */
106 tag [^\0\n>]+
107
108 /* Zero or more instances of backslash-newline. Following GCC, allow
109 white space between the backslash and the newline. */
110 splice (\\[ \f\t\v]*\n)*
111
112 %%
113 %{
114 /* Nesting level of the current code in braces. */
115 int braces_level IF_LINT (= 0);
116
117 /* Parent context state, when applicable. */
118 int context_state IF_LINT (= 0);
119
120 /* Location of most recent identifier, when applicable. */
121 location id_loc IF_LINT (= empty_location);
122
123 /* Where containing code started, when applicable. Its initial
124 value is relevant only when yylex is invoked in the SC_EPILOGUE
125 start condition. */
126 boundary code_start = scanner_cursor;
127
128 /* Where containing comment or string or character literal started,
129 when applicable. */
130 boundary token_start IF_LINT (= scanner_cursor);
131 %}
132
133
134 /*-----------------------.
135 | Scanning white space. |
136 `-----------------------*/
137
138 <INITIAL,SC_AFTER_IDENTIFIER>
139 {
140 /* Comments and white space. */
141 "," warn_at (*loc, _("stray `,' treated as white space"));
142 [ \f\n\t\v] |
143 "//".* ;
144 "/*" {
145 token_start = loc->start;
146 context_state = YY_START;
147 BEGIN SC_YACC_COMMENT;
148 }
149
150 /* #line directives are not documented, and may be withdrawn or
151 modified in future versions of Bison. */
152 ^"#line "{int}" \"".*"\"\n" {
153 handle_syncline (yytext + sizeof "#line " - 1, *loc);
154 }
155 }
156
157
158 /*----------------------------.
159 | Scanning Bison directives. |
160 `----------------------------*/
161 <INITIAL>
162 {
163 "%after-header" return PERCENT_AFTER_HEADER;
164 "%before-header" return PERCENT_BEFORE_HEADER;
165 "%binary" return PERCENT_NONASSOC;
166 "%debug" return PERCENT_DEBUG;
167 "%default"[-_]"prec" return PERCENT_DEFAULT_PREC;
168 "%define" return PERCENT_DEFINE;
169 "%defines" return PERCENT_DEFINES;
170 "%destructor" return PERCENT_DESTRUCTOR;
171 "%dprec" return PERCENT_DPREC;
172 "%end-header" return PERCENT_END_HEADER;
173 "%error"[-_]"verbose" return PERCENT_ERROR_VERBOSE;
174 "%expect" return PERCENT_EXPECT;
175 "%expect"[-_]"rr" return PERCENT_EXPECT_RR;
176 "%file-prefix" return PERCENT_FILE_PREFIX;
177 "%fixed"[-_]"output"[-_]"files" return PERCENT_YACC;
178 "%initial-action" return PERCENT_INITIAL_ACTION;
179 "%glr-parser" return PERCENT_GLR_PARSER;
180 "%left" return PERCENT_LEFT;
181 "%lex-param" return PERCENT_LEX_PARAM;
182 "%locations" return PERCENT_LOCATIONS;
183 "%merge" return PERCENT_MERGE;
184 "%name"[-_]"prefix" return PERCENT_NAME_PREFIX;
185 "%no"[-_]"default"[-_]"prec" return PERCENT_NO_DEFAULT_PREC;
186 "%no"[-_]"lines" return PERCENT_NO_LINES;
187 "%nonassoc" return PERCENT_NONASSOC;
188 "%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER;
189 "%nterm" return PERCENT_NTERM;
190 "%output" return PERCENT_OUTPUT;
191 "%parse-param" return PERCENT_PARSE_PARAM;
192 "%prec" return PERCENT_PREC;
193 "%printer" return PERCENT_PRINTER;
194 "%pure"[-_]"parser" return PERCENT_PURE_PARSER;
195 "%require" return PERCENT_REQUIRE;
196 "%right" return PERCENT_RIGHT;
197 "%skeleton" return PERCENT_SKELETON;
198 "%start" return PERCENT_START;
199 "%start-header" return PERCENT_START_HEADER;
200 "%term" return PERCENT_TOKEN;
201 "%token" return PERCENT_TOKEN;
202 "%token"[-_]"table" return PERCENT_TOKEN_TABLE;
203 "%type" return PERCENT_TYPE;
204 "%union" return PERCENT_UNION;
205 "%verbose" return PERCENT_VERBOSE;
206 "%yacc" return PERCENT_YACC;
207
208 {directive} {
209 complain_at (*loc, _("invalid directive: %s"), quote (yytext));
210 }
211
212 "=" return EQUAL;
213 "|" return PIPE;
214 ";" return SEMICOLON;
215
216 {id} {
217 val->uniqstr = uniqstr_new (yytext);
218 id_loc = *loc;
219 BEGIN SC_AFTER_IDENTIFIER;
220 }
221
222 {int} {
223 val->integer = scan_integer (yytext, 10, *loc);
224 return INT;
225 }
226 0[xX][0-9abcdefABCDEF]+ {
227 val->integer = scan_integer (yytext, 16, *loc);
228 return INT;
229 }
230
231 /* Characters. We don't check there is only one. */
232 "'" STRING_GROW; token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
233
234 /* Strings. */
235 "\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
236
237 /* Prologue. */
238 "%{" code_start = loc->start; BEGIN SC_PROLOGUE;
239
240 /* Code in between braces. */
241 "{" {
242 STRING_GROW;
243 braces_level = 0;
244 code_start = loc->start;
245 BEGIN SC_BRACED_CODE;
246 }
247
248 /* A type. */
249 "<"{tag}">" {
250 obstack_grow (&obstack_for_string, yytext + 1, yyleng - 2);
251 STRING_FINISH;
252 val->uniqstr = uniqstr_new (last_string);
253 STRING_FREE;
254 return TYPE;
255 }
256
257 "%%" {
258 static int percent_percent_count;
259 if (++percent_percent_count == 2)
260 BEGIN SC_EPILOGUE;
261 return PERCENT_PERCENT;
262 }
263
264 . {
265 complain_at (*loc, _("invalid character: %s"), quote (yytext));
266 }
267
268 <<EOF>> {
269 loc->start = loc->end = scanner_cursor;
270 yyterminate ();
271 }
272 }
273
274
275 /*-----------------------------------------------------------------.
276 | Scanning after an identifier, checking whether a colon is next. |
277 `-----------------------------------------------------------------*/
278
279 <SC_AFTER_IDENTIFIER>
280 {
281 ":" {
282 *loc = id_loc;
283 BEGIN INITIAL;
284 return ID_COLON;
285 }
286 . {
287 scanner_cursor.column -= mbsnwidth (yytext, yyleng, 0);
288 yyless (0);
289 *loc = id_loc;
290 BEGIN INITIAL;
291 return ID;
292 }
293 <<EOF>> {
294 *loc = id_loc;
295 BEGIN INITIAL;
296 return ID;
297 }
298 }
299
300
301 /*---------------------------------------------------------------.
302 | Scanning a Yacc comment. The initial `/ *' is already eaten. |
303 `---------------------------------------------------------------*/
304
305 <SC_YACC_COMMENT>
306 {
307 "*/" BEGIN context_state;
308 .|\n ;
309 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
310 }
311
312
313 /*------------------------------------------------------------.
314 | Scanning a C comment. The initial `/ *' is already eaten. |
315 `------------------------------------------------------------*/
316
317 <SC_COMMENT>
318 {
319 "*"{splice}"/" STRING_GROW; BEGIN context_state;
320 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
321 }
322
323
324 /*--------------------------------------------------------------.
325 | Scanning a line comment. The initial `//' is already eaten. |
326 `--------------------------------------------------------------*/
327
328 <SC_LINE_COMMENT>
329 {
330 "\n" STRING_GROW; BEGIN context_state;
331 {splice} STRING_GROW;
332 <<EOF>> BEGIN context_state;
333 }
334
335
336 /*------------------------------------------------.
337 | Scanning a Bison string, including its escapes. |
338 | The initial quote is already eaten. |
339 `------------------------------------------------*/
340
341 <SC_ESCAPED_STRING>
342 {
343 "\"" {
344 STRING_FINISH;
345 loc->start = token_start;
346 val->chars = last_string;
347 BEGIN INITIAL;
348 return STRING;
349 }
350 \n unexpected_newline (token_start, "\""); BEGIN INITIAL;
351 <<EOF>> unexpected_eof (token_start, "\""); BEGIN INITIAL;
352 }
353
354 /*----------------------------------------------------------.
355 | Scanning a Bison character literal, decoding its escapes. |
356 | The initial quote is already eaten. |
357 `----------------------------------------------------------*/
358
359 <SC_ESCAPED_CHARACTER>
360 {
361 "'" {
362 STRING_GROW;
363 STRING_FINISH;
364 loc->start = token_start;
365 val->character = last_string[1];
366 STRING_FREE;
367 BEGIN INITIAL;
368 return CHAR;
369 }
370 \n unexpected_newline (token_start, "'"); BEGIN INITIAL;
371 <<EOF>> unexpected_eof (token_start, "'"); BEGIN INITIAL;
372 }
373
374 <SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING>
375 {
376 \0 complain_at (*loc, _("invalid null character"));
377 }
378
379
380 /*----------------------------.
381 | Decode escaped characters. |
382 `----------------------------*/
383
384 <SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
385 {
386 \\[0-7]{1,3} {
387 unsigned long int c = strtoul (yytext + 1, NULL, 8);
388 if (UCHAR_MAX < c)
389 complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
390 else if (! c)
391 complain_at (*loc, _("invalid null character: %s"), quote (yytext));
392 else
393 obstack_1grow (&obstack_for_string, c);
394 }
395
396 \\x[0-9abcdefABCDEF]+ {
397 verify (UCHAR_MAX < ULONG_MAX);
398 unsigned long int c = strtoul (yytext + 2, NULL, 16);
399 if (UCHAR_MAX < c)
400 complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
401 else if (! c)
402 complain_at (*loc, _("invalid null character: %s"), quote (yytext));
403 else
404 obstack_1grow (&obstack_for_string, c);
405 }
406
407 \\a obstack_1grow (&obstack_for_string, '\a');
408 \\b obstack_1grow (&obstack_for_string, '\b');
409 \\f obstack_1grow (&obstack_for_string, '\f');
410 \\n obstack_1grow (&obstack_for_string, '\n');
411 \\r obstack_1grow (&obstack_for_string, '\r');
412 \\t obstack_1grow (&obstack_for_string, '\t');
413 \\v obstack_1grow (&obstack_for_string, '\v');
414
415 /* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
416 \\("\""|"'"|"?"|"\\") obstack_1grow (&obstack_for_string, yytext[1]);
417
418 \\(u|U[0-9abcdefABCDEF]{4})[0-9abcdefABCDEF]{4} {
419 int c = convert_ucn_to_byte (yytext);
420 if (c < 0)
421 complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
422 else if (! c)
423 complain_at (*loc, _("invalid null character: %s"), quote (yytext));
424 else
425 obstack_1grow (&obstack_for_string, c);
426 }
427 \\(.|\n) {
428 complain_at (*loc, _("unrecognized escape sequence: %s"), quote (yytext));
429 STRING_GROW;
430 }
431 }
432
433 /*--------------------------------------------.
434 | Scanning user-code characters and strings. |
435 `--------------------------------------------*/
436
437 <SC_CHARACTER,SC_STRING>
438 {
439 {splice}|\\{splice}[^\n\[\]] STRING_GROW;
440 }
441
442 <SC_CHARACTER>
443 {
444 "'" STRING_GROW; BEGIN context_state;
445 \n unexpected_newline (token_start, "'"); BEGIN context_state;
446 <<EOF>> unexpected_eof (token_start, "'"); BEGIN context_state;
447 }
448
449 <SC_STRING>
450 {
451 "\"" STRING_GROW; BEGIN context_state;
452 \n unexpected_newline (token_start, "\""); BEGIN context_state;
453 <<EOF>> unexpected_eof (token_start, "\""); BEGIN context_state;
454 }
455
456
457 /*---------------------------------------------------.
458 | Strings, comments etc. can be found in user code. |
459 `---------------------------------------------------*/
460
461 <SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE>
462 {
463 "'" {
464 STRING_GROW;
465 context_state = YY_START;
466 token_start = loc->start;
467 BEGIN SC_CHARACTER;
468 }
469 "\"" {
470 STRING_GROW;
471 context_state = YY_START;
472 token_start = loc->start;
473 BEGIN SC_STRING;
474 }
475 "/"{splice}"*" {
476 STRING_GROW;
477 context_state = YY_START;
478 token_start = loc->start;
479 BEGIN SC_COMMENT;
480 }
481 "/"{splice}"/" {
482 STRING_GROW;
483 context_state = YY_START;
484 BEGIN SC_LINE_COMMENT;
485 }
486 }
487
488
489
490 /*-----------------------------------------------------------.
491 | Scanning some code in braces (actions). The initial "{" is |
492 | already eaten. |
493 `-----------------------------------------------------------*/
494
495 <SC_BRACED_CODE>
496 {
497 "{"|"<"{splice}"%" STRING_GROW; braces_level++;
498 "%"{splice}">" STRING_GROW; braces_level--;
499 "}" {
500 obstack_1grow (&obstack_for_string, '}');
501
502 --braces_level;
503 if (braces_level < 0)
504 {
505 STRING_FINISH;
506 loc->start = code_start;
507 val->chars = last_string;
508 gram_last_braced_code_loc = *loc;
509 BEGIN INITIAL;
510 return BRACED_CODE;
511 }
512 }
513
514 /* Tokenize `<<%' correctly (as `<<' `%') rather than incorrrectly
515 (as `<' `<%'). */
516 "<"{splice}"<" STRING_GROW;
517
518 <<EOF>> unexpected_eof (code_start, "}"); BEGIN INITIAL;
519 }
520
521
522 /*--------------------------------------------------------------.
523 | Scanning some prologue: from "%{" (already scanned) to "%}". |
524 `--------------------------------------------------------------*/
525
526 <SC_PROLOGUE>
527 {
528 "%}" {
529 STRING_FINISH;
530 loc->start = code_start;
531 val->chars = last_string;
532 BEGIN INITIAL;
533 return PROLOGUE;
534 }
535
536 <<EOF>> unexpected_eof (code_start, "%}"); BEGIN INITIAL;
537 }
538
539
540 /*---------------------------------------------------------------.
541 | Scanning the epilogue (everything after the second "%%", which |
542 | has already been eaten). |
543 `---------------------------------------------------------------*/
544
545 <SC_EPILOGUE>
546 {
547 <<EOF>> {
548 STRING_FINISH;
549 loc->start = code_start;
550 val->chars = last_string;
551 BEGIN INITIAL;
552 return EPILOGUE;
553 }
554 }
555
556
557 /*-----------------------------------------------------.
558 | By default, grow the string obstack with the input. |
559 `-----------------------------------------------------*/
560
561 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>. |
562 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE>\n STRING_GROW;
563
564 %%
565
566 /* Read bytes from FP into buffer BUF of size SIZE. Return the
567 number of bytes read. Remove '\r' from input, treating \r\n
568 and isolated \r as \n. */
569
570 static size_t
571 no_cr_read (FILE *fp, char *buf, size_t size)
572 {
573 size_t bytes_read = fread (buf, 1, size, fp);
574 if (bytes_read)
575 {
576 char *w = memchr (buf, '\r', bytes_read);
577 if (w)
578 {
579 char const *r = ++w;
580 char const *lim = buf + bytes_read;
581
582 for (;;)
583 {
584 /* Found an '\r'. Treat it like '\n', but ignore any
585 '\n' that immediately follows. */
586 w[-1] = '\n';
587 if (r == lim)
588 {
589 int ch = getc (fp);
590 if (ch != '\n' && ungetc (ch, fp) != ch)
591 break;
592 }
593 else if (*r == '\n')
594 r++;
595
596 /* Copy until the next '\r'. */
597 do
598 {
599 if (r == lim)
600 return w - buf;
601 }
602 while ((*w++ = *r++) != '\r');
603 }
604
605 return w - buf;
606 }
607 }
608
609 return bytes_read;
610 }
611
612
613
614 /*------------------------------------------------------.
615 | Scan NUMBER for a base-BASE integer at location LOC. |
616 `------------------------------------------------------*/
617
618 static unsigned long int
619 scan_integer (char const *number, int base, location loc)
620 {
621 verify (INT_MAX < ULONG_MAX);
622 unsigned long int num = strtoul (number, NULL, base);
623
624 if (INT_MAX < num)
625 {
626 complain_at (loc, _("integer out of range: %s"), quote (number));
627 num = INT_MAX;
628 }
629
630 return num;
631 }
632
633
634 /*------------------------------------------------------------------.
635 | Convert universal character name UCN to a single-byte character, |
636 | and return that character. Return -1 if UCN does not correspond |
637 | to a single-byte character. |
638 `------------------------------------------------------------------*/
639
640 static int
641 convert_ucn_to_byte (char const *ucn)
642 {
643 verify (UCHAR_MAX <= INT_MAX);
644 unsigned long int code = strtoul (ucn + 2, NULL, 16);
645
646 /* FIXME: Currently we assume Unicode-compatible unibyte characters
647 on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
648 non-ASCII hosts we support only the portable C character set.
649 These limitations should be removed once we add support for
650 multibyte characters. */
651
652 if (UCHAR_MAX < code)
653 return -1;
654
655 #if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
656 {
657 /* A non-ASCII host. Use CODE to index into a table of the C
658 basic execution character set, which is guaranteed to exist on
659 all Standard C platforms. This table also includes '$', '@',
660 and '`', which are not in the basic execution character set but
661 which are unibyte characters on all the platforms that we know
662 about. */
663 static signed char const table[] =
664 {
665 '\0', -1, -1, -1, -1, -1, -1, '\a',
666 '\b', '\t', '\n', '\v', '\f', '\r', -1, -1,
667 -1, -1, -1, -1, -1, -1, -1, -1,
668 -1, -1, -1, -1, -1, -1, -1, -1,
669 ' ', '!', '"', '#', '$', '%', '&', '\'',
670 '(', ')', '*', '+', ',', '-', '.', '/',
671 '0', '1', '2', '3', '4', '5', '6', '7',
672 '8', '9', ':', ';', '<', '=', '>', '?',
673 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
674 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
675 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
676 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
677 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
678 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
679 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
680 'x', 'y', 'z', '{', '|', '}', '~'
681 };
682
683 code = code < sizeof table ? table[code] : -1;
684 }
685 #endif
686
687 return code;
688 }
689
690
691 /*----------------------------------------------------------------.
692 | Handle `#line INT "FILE"'. ARGS has already skipped `#line '. |
693 `----------------------------------------------------------------*/
694
695 static void
696 handle_syncline (char *args, location loc)
697 {
698 char *after_num;
699 unsigned long int lineno = strtoul (args, &after_num, 10);
700 char *file = strchr (after_num, '"') + 1;
701 *strchr (file, '"') = '\0';
702 if (INT_MAX <= lineno)
703 {
704 warn_at (loc, _("line number overflow"));
705 lineno = INT_MAX;
706 }
707 current_file = uniqstr_new (file);
708 boundary_set (&scanner_cursor, current_file, lineno, 1);
709 }
710
711
712 /*----------------------------------------------------------------.
713 | For a token or comment starting at START, report message MSGID, |
714 | which should say that an end marker was found before |
715 | the expected TOKEN_END. |
716 `----------------------------------------------------------------*/
717
718 static void
719 unexpected_end (boundary start, char const *msgid, char const *token_end)
720 {
721 location loc;
722 loc.start = start;
723 loc.end = scanner_cursor;
724 complain_at (loc, _(msgid), token_end);
725 }
726
727
728 /*------------------------------------------------------------------------.
729 | Report an unexpected EOF in a token or comment starting at START. |
730 | An end of file was encountered and the expected TOKEN_END was missing. |
731 `------------------------------------------------------------------------*/
732
733 static void
734 unexpected_eof (boundary start, char const *token_end)
735 {
736 unexpected_end (start, N_("missing `%s' at end of file"), token_end);
737 }
738
739
740 /*----------------------------------------.
741 | Likewise, but for unexpected newlines. |
742 `----------------------------------------*/
743
744 static void
745 unexpected_newline (boundary start, char const *token_end)
746 {
747 unexpected_end (start, N_("missing `%s' at end of line"), token_end);
748 }
749
750
751 /*-------------------------.
752 | Initialize the scanner. |
753 `-------------------------*/
754
755 void
756 gram_scanner_initialize (void)
757 {
758 obstack_init (&obstack_for_string);
759 }
760
761
762 /*-----------------------------------------------.
763 | Free all the memory allocated to the scanner. |
764 `-----------------------------------------------*/
765
766 void
767 gram_scanner_free (void)
768 {
769 obstack_free (&obstack_for_string, 0);
770 /* Reclaim Flex's buffers. */
771 yy_delete_buffer (YY_CURRENT_BUFFER);
772 }