1 /* Bison Grammar Scanner -*- C -*-
3 Copyright (C) 2002-2013 Free Software Foundation, Inc.
5 This file is part of Bison, the GNU Compiler Compiler.
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 %option debug nodefault noinput noyywrap never-interactive
21 %option prefix="gram_" outfile="lex.yy.c"
24 /* Work around a bug in flex 2.5.31. See Debian bug 333231
25 <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
29 #define FLEX_PREFIX(Id) gram_ ## Id
30 #include <src/flex-scanner.h>
32 #include <src/complain.h>
33 #include <src/files.h>
34 #include <src/getargs.h>
37 #include <src/reader.h>
38 #include <src/uniqstr.h>
44 #include <src/scan-gram.h>
46 #define YY_DECL GRAM_LEX_DECL
48 #define YY_USER_INIT \
49 code_start = scanner_cursor = loc->start; \
51 /* Location of scanner cursor. */
52 static boundary scanner_cursor;
54 #define YY_USER_ACTION location_compute (loc, &scanner_cursor, yytext, yyleng);
56 static size_t no_cr_read (FILE *, char *, size_t);
57 #define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
59 #define RETURN_PERCENT_PARAM(Value) \
60 RETURN_VALUE(PERCENT_PARAM, param, param_ ## Value)
62 #define RETURN_PERCENT_FLAG(Value) \
63 RETURN_VALUE(PERCENT_FLAG, uniqstr, uniqstr_new (Value))
65 #define RETURN_VALUE(Token, Field, Value) \
71 #define ROLLBACK_CURRENT_TOKEN \
73 scanner_cursor.column -= mbsnwidth (yytext, yyleng, 0); \
77 #define DEPRECATED(Msg) \
80 deprecated_directive (loc, yytext, Msg); \
81 scanner_cursor.column -= mbsnwidth (Msg, strlen (Msg), 0); \
82 for (i = strlen (Msg); i != 0; --i) \
86 /* A string representing the most recently saved token. */
87 static char *last_string;
89 /* Bracketed identifier. */
90 static uniqstr bracketed_id_str = 0;
91 static location bracketed_id_loc;
92 static boundary bracketed_id_start;
93 static int bracketed_id_context_state = 0;
96 gram_scanner_last_string_free (void)
101 static void handle_syncline (char *, location);
102 static unsigned long int scan_integer (char const *p, int base, location loc);
103 static int convert_ucn_to_byte (char const *hex_text);
104 static void unexpected_eof (boundary, char const *);
105 static void unexpected_newline (boundary, char const *);
108 /* A C-like comment in directives/rules. */
110 /* Strings and characters in directives/rules. */
111 %x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
112 /* A identifier was just read in directives/rules. Special state
113 to capture the sequence 'identifier :'. */
114 %x SC_AFTER_IDENTIFIER
116 /* POSIX says that a tag must be both an id and a C union member, but
117 historically almost any character is allowed in a tag. We
118 disallow NUL, as this simplifies our implementation. We match
119 angle brackets in nested pairs: several languages use them for
120 generics/template types. */
123 /* Four types of user code:
124 - prologue (code between '%{' '%}' in the first section, before %%);
125 - actions, printers, union, etc, (between braced in the middle section);
126 - epilogue (everything after the second %%).
127 - predicate (code between '%?{' and '{' in middle section); */
128 %x SC_PROLOGUE SC_BRACED_CODE SC_EPILOGUE SC_PREDICATE
129 /* C and C++ comments in code. */
130 %x SC_COMMENT SC_LINE_COMMENT
131 /* Strings and characters in code. */
132 %x SC_STRING SC_CHARACTER
133 /* Bracketed identifiers support. */
134 %x SC_BRACKETED_ID SC_RETURN_BRACKETED_ID
136 letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
137 notletter [^.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]{-}[%\{]
138 id {letter}({letter}|[-0-9])*
141 /* Zero or more instances of backslash-newline. Following GCC, allow
142 white space between the backslash and the newline. */
143 splice (\\[ \f\t\v]*\n)*
145 /* An equal sign, with optional leading whitespaces. This is used in some
146 deprecated constructs. */
147 eqopt ([[:space:]]*=)?
151 /* Nesting level. Either for nested braces, or nested angle brackets
153 int nesting PACIFY_CC (= 0);
155 /* Parent context state, when applicable. */
156 int context_state PACIFY_CC (= 0);
158 /* Location of most recent identifier, when applicable. */
159 location id_loc PACIFY_CC (= empty_location);
161 /* Where containing code started, when applicable. Its initial
162 value is relevant only when yylex is invoked in the SC_EPILOGUE
164 boundary code_start = scanner_cursor;
166 /* Where containing comment or string or character literal started,
168 boundary token_start PACIFY_CC (= scanner_cursor);
172 /*-----------------------.
173 | Scanning white space. |
174 `-----------------------*/
176 <INITIAL,SC_AFTER_IDENTIFIER,SC_BRACKETED_ID,SC_RETURN_BRACKETED_ID>
178 /* Comments and white space. */
180 complain (loc, Wother, _("stray ',' treated as white space"));
185 token_start = loc->start;
186 context_state = YY_START;
187 BEGIN SC_YACC_COMMENT;
190 /* #line directives are not documented, and may be withdrawn or
191 modified in future versions of Bison. */
192 ^"#line "{int}(" \"".*"\"")?"\n" {
193 handle_syncline (yytext + sizeof "#line " - 1, *loc);
198 /*----------------------------.
199 | Scanning Bison directives. |
200 `----------------------------*/
202 /* For directives that are also command line options, the regex must be
204 after "[-_]"s are removed, and the directive must match the --long
205 option name, with a single string argument. Otherwise, add exceptions
206 to ../build-aux/cross-options.pl. */
210 "%binary" return PERCENT_NONASSOC;
211 "%code" return PERCENT_CODE;
212 "%debug" RETURN_PERCENT_FLAG("parse.trace");
213 "%default-prec" return PERCENT_DEFAULT_PREC;
214 "%define" return PERCENT_DEFINE;
215 "%defines" return PERCENT_DEFINES;
216 "%destructor" return PERCENT_DESTRUCTOR;
217 "%dprec" return PERCENT_DPREC;
218 "%empty" return PERCENT_EMPTY;
219 "%error-verbose" return PERCENT_ERROR_VERBOSE;
220 "%expect" return PERCENT_EXPECT;
221 "%expect-rr" return PERCENT_EXPECT_RR;
222 "%file-prefix" return PERCENT_FILE_PREFIX;
223 "%fixed-output-files" return PERCENT_YACC;
224 "%initial-action" return PERCENT_INITIAL_ACTION;
225 "%glr-parser" return PERCENT_GLR_PARSER;
226 "%language" return PERCENT_LANGUAGE;
227 "%left" return PERCENT_LEFT;
228 "%lex-param" RETURN_PERCENT_PARAM(lex);
229 "%locations" RETURN_PERCENT_FLAG("locations");
230 "%merge" return PERCENT_MERGE;
231 "%name-prefix" return PERCENT_NAME_PREFIX;
232 "%no-default-prec" return PERCENT_NO_DEFAULT_PREC;
233 "%no-lines" return PERCENT_NO_LINES;
234 "%nonassoc" return PERCENT_NONASSOC;
235 "%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER;
236 "%nterm" return PERCENT_NTERM;
237 "%output" return PERCENT_OUTPUT;
238 "%param" RETURN_PERCENT_PARAM(both);
239 "%parse-param" RETURN_PERCENT_PARAM(parse);
240 "%prec" return PERCENT_PREC;
241 "%precedence" return PERCENT_PRECEDENCE;
242 "%printer" return PERCENT_PRINTER;
243 "%pure-parser" RETURN_PERCENT_FLAG("api.pure");
244 "%require" return PERCENT_REQUIRE;
245 "%right" return PERCENT_RIGHT;
246 "%skeleton" return PERCENT_SKELETON;
247 "%start" return PERCENT_START;
248 "%term" return PERCENT_TOKEN;
249 "%token" return PERCENT_TOKEN;
250 "%token-table" return PERCENT_TOKEN_TABLE;
251 "%type" return PERCENT_TYPE;
252 "%union" return PERCENT_UNION;
253 "%verbose" return PERCENT_VERBOSE;
254 "%yacc" return PERCENT_YACC;
257 "%default"[-_]"prec" DEPRECATED("%default-prec");
258 "%error"[-_]"verbose" DEPRECATED("%define parse.error verbose");
259 "%expect"[-_]"rr" DEPRECATED("%expect-rr");
260 "%file-prefix"{eqopt} DEPRECATED("%file-prefix");
261 "%fixed"[-_]"output"[-_]"files" DEPRECATED("%fixed-output-files");
262 "%name"[-_]"prefix"{eqopt} DEPRECATED("%name-prefix");
263 "%no"[-_]"default"[-_]"prec" DEPRECATED("%no-default-prec");
264 "%no"[-_]"lines" DEPRECATED("%no-lines");
265 "%output"{eqopt} DEPRECATED("%output");
266 "%pure"[-_]"parser" DEPRECATED("%pure-parser");
267 "%token"[-_]"table" DEPRECATED("%token-table");
269 "%"{id}|"%"{notletter}([[:graph:]])+ {
270 complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
275 ";" return SEMICOLON;
278 val->uniqstr = uniqstr_new (yytext);
280 bracketed_id_str = NULL;
281 BEGIN SC_AFTER_IDENTIFIER;
285 val->integer = scan_integer (yytext, 10, *loc);
288 0[xX][0-9abcdefABCDEF]+ {
289 val->integer = scan_integer (yytext, 16, *loc);
293 /* Identifiers may not start with a digit. Yet, don't silently
294 accept "1FOO" as "1 FOO". */
296 complain (loc, complaint, _("invalid identifier: %s"), quote (yytext));
300 "'" token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
303 "\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
306 "%{" code_start = loc->start; BEGIN SC_PROLOGUE;
308 /* Code in between braces. */
312 code_start = loc->start;
313 BEGIN SC_BRACED_CODE;
316 /* Semantic predicate. */
317 "%?"[ \f\n\t\v]*"{" {
319 code_start = loc->start;
324 "<*>" return TAG_ANY;
325 "<>" return TAG_NONE;
328 token_start = loc->start;
333 static int percent_percent_count;
334 if (++percent_percent_count == 2)
336 return PERCENT_PERCENT;
340 bracketed_id_str = NULL;
341 bracketed_id_start = loc->start;
342 bracketed_id_context_state = YY_START;
343 BEGIN SC_BRACKETED_ID;
346 [^\[%A-Za-z0-9_<>{}\"\'*;|=/, \f\n\t\v]+|. {
347 complain (loc, complaint, "%s: %s",
348 ngettext ("invalid character", "invalid characters", yyleng),
349 quote_mem (yytext, yyleng));
353 loc->start = loc->end = scanner_cursor;
359 /*--------------------------------------------------------------.
360 | Supporting \0 complexifies our implementation for no expected |
362 `--------------------------------------------------------------*/
364 <SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_TAG>
366 \0 complain (loc, complaint, _("invalid null character"));
370 /*-----------------------------------------------------------------.
371 | Scanning after an identifier, checking whether a colon is next. |
372 `-----------------------------------------------------------------*/
374 <SC_AFTER_IDENTIFIER>
377 if (bracketed_id_str)
379 ROLLBACK_CURRENT_TOKEN;
380 BEGIN SC_RETURN_BRACKETED_ID;
386 bracketed_id_start = loc->start;
387 bracketed_id_context_state = YY_START;
388 BEGIN SC_BRACKETED_ID;
392 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
397 ROLLBACK_CURRENT_TOKEN;
398 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
403 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
409 /*--------------------------------.
410 | Scanning bracketed identifiers. |
411 `--------------------------------*/
416 if (bracketed_id_str)
418 complain (loc, complaint,
419 _("unexpected identifier in bracketed name: %s"),
424 bracketed_id_str = uniqstr_new (yytext);
425 bracketed_id_loc = *loc;
429 BEGIN bracketed_id_context_state;
430 if (bracketed_id_str)
432 if (INITIAL == bracketed_id_context_state)
434 val->uniqstr = bracketed_id_str;
435 bracketed_id_str = 0;
436 *loc = bracketed_id_loc;
441 complain (loc, complaint, _("an identifier expected"));
444 [^\].A-Za-z0-9_/ \f\n\t\v]+|. {
445 complain (loc, complaint, "%s: %s",
446 ngettext ("invalid character in bracketed name",
447 "invalid characters in bracketed name", yyleng),
448 quote_mem (yytext, yyleng));
452 BEGIN bracketed_id_context_state;
453 unexpected_eof (bracketed_id_start, "]");
457 <SC_RETURN_BRACKETED_ID>
460 ROLLBACK_CURRENT_TOKEN;
461 val->uniqstr = bracketed_id_str;
462 bracketed_id_str = 0;
463 *loc = bracketed_id_loc;
470 /*---------------------------------------------------------------.
471 | Scanning a Yacc comment. The initial '/ *' is already eaten. |
472 `---------------------------------------------------------------*/
476 "*/" BEGIN context_state;
478 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
482 /*------------------------------------------------------------.
483 | Scanning a C comment. The initial '/ *' is already eaten. |
484 `------------------------------------------------------------*/
488 "*"{splice}"/" STRING_GROW; BEGIN context_state;
489 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
493 /*--------------------------------------------------------------.
494 | Scanning a line comment. The initial '//' is already eaten. |
495 `--------------------------------------------------------------*/
499 "\n" STRING_GROW; BEGIN context_state;
500 {splice} STRING_GROW;
501 <<EOF>> BEGIN context_state;
505 /*------------------------------------------------.
506 | Scanning a Bison string, including its escapes. |
507 | The initial quote is already eaten. |
508 `------------------------------------------------*/
514 loc->start = token_start;
515 val->chars = last_string;
519 <<EOF>> unexpected_eof (token_start, "\"");
520 "\n" unexpected_newline (token_start, "\"");
523 /*----------------------------------------------------------.
524 | Scanning a Bison character literal, decoding its escapes. |
525 | The initial quote is already eaten. |
526 `----------------------------------------------------------*/
528 <SC_ESCAPED_CHARACTER>
532 loc->start = token_start;
533 val->character = last_string[0];
535 /* FIXME: Eventually, make these errors. */
536 if (last_string[0] == '\0')
538 complain (loc, Wother, _("empty character literal"));
539 /* '\0' seems dangerous even if we are about to complain. */
540 val->character = '\'';
542 else if (last_string[1] != '\0')
543 complain (loc, Wother,
544 _("extra characters in character literal"));
549 "\n" unexpected_newline (token_start, "'");
550 <<EOF>> unexpected_eof (token_start, "'");
555 /*--------------------------------------------------------------.
556 | Scanning a tag. The initial angle bracket is already eaten. |
557 `--------------------------------------------------------------*/
566 loc->start = token_start;
567 val->uniqstr = uniqstr_new (last_string);
575 ([^<>]|->)+ STRING_GROW;
576 "<"+ STRING_GROW; nesting += yyleng;
578 <<EOF>> unexpected_eof (token_start, ">");
581 /*----------------------------.
582 | Decode escaped characters. |
583 `----------------------------*/
585 <SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
588 unsigned long int c = strtoul (yytext + 1, NULL, 8);
589 if (!c || UCHAR_MAX < c)
590 complain (loc, complaint, _("invalid number after \\-escape: %s"),
593 obstack_1grow (&obstack_for_string, c);
596 \\x[0-9abcdefABCDEF]+ {
597 verify (UCHAR_MAX < ULONG_MAX);
598 unsigned long int c = strtoul (yytext + 2, NULL, 16);
599 if (!c || UCHAR_MAX < c)
600 complain (loc, complaint, _("invalid number after \\-escape: %s"),
603 obstack_1grow (&obstack_for_string, c);
606 \\a obstack_1grow (&obstack_for_string, '\a');
607 \\b obstack_1grow (&obstack_for_string, '\b');
608 \\f obstack_1grow (&obstack_for_string, '\f');
609 \\n obstack_1grow (&obstack_for_string, '\n');
610 \\r obstack_1grow (&obstack_for_string, '\r');
611 \\t obstack_1grow (&obstack_for_string, '\t');
612 \\v obstack_1grow (&obstack_for_string, '\v');
614 /* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
615 \\("\""|"'"|"?"|"\\") obstack_1grow (&obstack_for_string, yytext[1]);
617 \\(u|U[0-9abcdefABCDEF]{4})[0-9abcdefABCDEF]{4} {
618 int c = convert_ucn_to_byte (yytext);
620 complain (loc, complaint, _("invalid number after \\-escape: %s"),
623 obstack_1grow (&obstack_for_string, c);
626 char const *p = yytext + 1;
627 /* Quote only if escaping won't make the character visible. */
628 if (c_isspace ((unsigned char) *p) && c_isprint ((unsigned char) *p))
631 p = quotearg_style_mem (escape_quoting_style, p, 1);
632 complain (loc, complaint, _("invalid character after \\-escape: %s"),
637 /*--------------------------------------------.
638 | Scanning user-code characters and strings. |
639 `--------------------------------------------*/
641 <SC_CHARACTER,SC_STRING>
643 {splice}|\\{splice}[^\n\[\]] STRING_GROW;
648 "'" STRING_GROW; BEGIN context_state;
649 \n unexpected_newline (token_start, "'");
650 <<EOF>> unexpected_eof (token_start, "'");
655 "\"" STRING_GROW; BEGIN context_state;
656 \n unexpected_newline (token_start, "\"");
657 <<EOF>> unexpected_eof (token_start, "\"");
661 /*---------------------------------------------------.
662 | Strings, comments etc. can be found in user code. |
663 `---------------------------------------------------*/
665 <SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE,SC_PREDICATE>
669 context_state = YY_START;
670 token_start = loc->start;
675 context_state = YY_START;
676 token_start = loc->start;
681 context_state = YY_START;
682 token_start = loc->start;
687 context_state = YY_START;
688 BEGIN SC_LINE_COMMENT;
694 /*-----------------------------------------------------------.
695 | Scanning some code in braces (actions, predicates). The |
696 | initial "{" is already eaten. |
697 `-----------------------------------------------------------*/
699 <SC_BRACED_CODE,SC_PREDICATE>
701 "{"|"<"{splice}"%" STRING_GROW; nesting++;
702 "%"{splice}">" STRING_GROW; nesting--;
704 /* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly
706 "<"{splice}"<" STRING_GROW;
708 <<EOF>> unexpected_eof (code_start, "}");
714 obstack_1grow (&obstack_for_string, '}');
720 loc->start = code_start;
721 val->code = last_string;
735 loc->start = code_start;
736 val->code = last_string;
738 return BRACED_PREDICATE;
741 obstack_1grow (&obstack_for_string, '}');
745 /*--------------------------------------------------------------.
746 | Scanning some prologue: from "%{" (already scanned) to "%}". |
747 `--------------------------------------------------------------*/
753 loc->start = code_start;
754 val->chars = last_string;
759 <<EOF>> unexpected_eof (code_start, "%}");
763 /*---------------------------------------------------------------.
764 | Scanning the epilogue (everything after the second "%%", which |
765 | has already been eaten). |
766 `---------------------------------------------------------------*/
772 loc->start = code_start;
773 val->chars = last_string;
780 /*-----------------------------------------------------.
781 | By default, grow the string obstack with the input. |
782 `-----------------------------------------------------*/
784 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>. |
785 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE>\n STRING_GROW;
789 /* Read bytes from FP into buffer BUF of size SIZE. Return the
790 number of bytes read. Remove '\r' from input, treating \r\n
791 and isolated \r as \n. */
794 no_cr_read (FILE *fp, char *buf, size_t size)
796 size_t bytes_read = fread (buf, 1, size, fp);
799 char *w = memchr (buf, '\r', bytes_read);
803 char const *lim = buf + bytes_read;
807 /* Found an '\r'. Treat it like '\n', but ignore any
808 '\n' that immediately follows. */
813 if (ch != '\n' && ungetc (ch, fp) != ch)
819 /* Copy until the next '\r'. */
825 while ((*w++ = *r++) != '\r');
837 /*------------------------------------------------------.
838 | Scan NUMBER for a base-BASE integer at location LOC. |
839 `------------------------------------------------------*/
841 static unsigned long int
842 scan_integer (char const *number, int base, location loc)
844 verify (INT_MAX < ULONG_MAX);
845 unsigned long int num = strtoul (number, NULL, base);
849 complain (&loc, complaint, _("integer out of range: %s"),
858 /*------------------------------------------------------------------.
859 | Convert universal character name UCN to a single-byte character, |
860 | and return that character. Return -1 if UCN does not correspond |
861 | to a single-byte character. |
862 `------------------------------------------------------------------*/
865 convert_ucn_to_byte (char const *ucn)
867 verify (UCHAR_MAX <= INT_MAX);
868 unsigned long int code = strtoul (ucn + 2, NULL, 16);
870 /* FIXME: Currently we assume Unicode-compatible unibyte characters
871 on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
872 non-ASCII hosts we support only the portable C character set.
873 These limitations should be removed once we add support for
874 multibyte characters. */
876 if (UCHAR_MAX < code)
879 #if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
881 /* A non-ASCII host. Use CODE to index into a table of the C
882 basic execution character set, which is guaranteed to exist on
883 all Standard C platforms. This table also includes '$', '@',
884 and '`', which are not in the basic execution character set but
885 which are unibyte characters on all the platforms that we know
887 static signed char const table[] =
889 '\0', -1, -1, -1, -1, -1, -1, '\a',
890 '\b', '\t', '\n', '\v', '\f', '\r', -1, -1,
891 -1, -1, -1, -1, -1, -1, -1, -1,
892 -1, -1, -1, -1, -1, -1, -1, -1,
893 ' ', '!', '"', '#', '$', '%', '&', '\'',
894 '(', ')', '*', '+', ',', '-', '.', '/',
895 '0', '1', '2', '3', '4', '5', '6', '7',
896 '8', '9', ':', ';', '<', '=', '>', '?',
897 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
898 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
899 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
900 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
901 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
902 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
903 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
904 'x', 'y', 'z', '{', '|', '}', '~'
907 code = code < sizeof table ? table[code] : -1;
915 /*---------------------------------------------------------------------.
916 | Handle '#line INT( "FILE")?\n'. ARGS has already skipped '#line '. |
917 `---------------------------------------------------------------------*/
920 handle_syncline (char *args, location loc)
923 unsigned long int lineno = strtoul (args, &file, 10);
924 if (INT_MAX <= lineno)
926 complain (&loc, Wother, _("line number overflow"));
930 file = strchr (file, '"');
933 *strchr (file + 1, '"') = '\0';
934 current_file = uniqstr_new (file + 1);
936 boundary_set (&scanner_cursor, current_file, lineno, 1);
940 /*----------------------------------------------------------------.
941 | For a token or comment starting at START, report message MSGID, |
942 | which should say that an end marker was found before the |
943 | expected TOKEN_END. Then, pretend that TOKEN_END was found. |
944 `----------------------------------------------------------------*/
947 unexpected_end (boundary start, char const *msgid, char const *token_end)
951 loc.end = scanner_cursor;
952 size_t i = strlen (token_end);
954 /* Adjust scanner cursor so that any later message does not count
955 the characters about to be inserted. */
956 scanner_cursor.column -= i;
959 unput (token_end[--i]);
961 token_end = quote (token_end);
962 /* Instead of '\'', display "'". */
963 if (STREQ (token_end, "'\\''"))
965 complain (&loc, complaint, _(msgid), token_end);
969 /*------------------------------------------------------------------------.
970 | Report an unexpected EOF in a token or comment starting at START. |
971 | An end of file was encountered and the expected TOKEN_END was missing. |
972 | After reporting the problem, pretend that TOKEN_END was found. |
973 `------------------------------------------------------------------------*/
976 unexpected_eof (boundary start, char const *token_end)
978 unexpected_end (start, N_("missing %s at end of file"), token_end);
982 /*----------------------------------------.
983 | Likewise, but for unexpected newlines. |
984 `----------------------------------------*/
987 unexpected_newline (boundary start, char const *token_end)
989 unexpected_end (start, N_("missing %s at end of line"), token_end);
993 /*-------------------------.
994 | Initialize the scanner. |
995 `-------------------------*/
998 gram_scanner_initialize (void)
1000 obstack_init (&obstack_for_string);
1004 /*-----------------------------------------------.
1005 | Free all the memory allocated to the scanner. |
1006 `-----------------------------------------------*/
1009 gram_scanner_free (void)
1011 obstack_free (&obstack_for_string, 0);
1012 /* Reclaim Flex's buffers. */