1 /* Bison Grammar Scanner -*- C -*-
3 Copyright (C) 2002-2015 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 /* Location of scanner cursor. */
49 static boundary scanner_cursor;
51 #define YY_USER_ACTION location_compute (loc, &scanner_cursor, yytext, yyleng);
53 static size_t no_cr_read (FILE *, char *, size_t);
54 #define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
56 #define RETURN_PERCENT_PARAM(Value) \
57 RETURN_VALUE(PERCENT_PARAM, param, param_ ## Value)
59 #define RETURN_PERCENT_FLAG(Value) \
60 RETURN_VALUE(PERCENT_FLAG, uniqstr, uniqstr_new (Value))
62 #define RETURN_VALUE(Token, Field, Value) \
68 #define ROLLBACK_CURRENT_TOKEN \
70 scanner_cursor.column -= mbsnwidth (yytext, yyleng, 0); \
74 #define DEPRECATED(Msg) \
77 deprecated_directive (loc, yytext, Msg); \
78 scanner_cursor.column -= mbsnwidth (Msg, strlen (Msg), 0); \
79 for (i = strlen (Msg); i != 0; --i) \
83 /* A string representing the most recently saved token. */
84 static char *last_string;
86 /* Bracketed identifier. */
87 static uniqstr bracketed_id_str = 0;
88 static location bracketed_id_loc;
89 static boundary bracketed_id_start;
90 static int bracketed_id_context_state = 0;
93 gram_scanner_last_string_free (void)
98 static void handle_syncline (char *, location);
99 static unsigned long int scan_integer (char const *p, int base, location loc);
100 static int convert_ucn_to_byte (char const *hex_text);
101 static void unexpected_eof (boundary, char const *);
102 static void unexpected_newline (boundary, char const *);
105 /* A C-like comment in directives/rules. */
107 /* Strings and characters in directives/rules. */
108 %x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
109 /* A identifier was just read in directives/rules. Special state
110 to capture the sequence 'identifier :'. */
111 %x SC_AFTER_IDENTIFIER
113 /* POSIX says that a tag must be both an id and a C union member, but
114 historically almost any character is allowed in a tag. We
115 disallow NUL, as this simplifies our implementation. We match
116 angle brackets in nested pairs: several languages use them for
117 generics/template types. */
120 /* Four types of user code:
121 - prologue (code between '%{' '%}' in the first section, before %%);
122 - actions, printers, union, etc, (between braced in the middle section);
123 - epilogue (everything after the second %%).
124 - predicate (code between '%?{' and '{' in middle section); */
125 %x SC_PROLOGUE SC_BRACED_CODE SC_EPILOGUE SC_PREDICATE
126 /* C and C++ comments in code. */
127 %x SC_COMMENT SC_LINE_COMMENT
128 /* Strings and characters in code. */
129 %x SC_STRING SC_CHARACTER
130 /* Bracketed identifiers support. */
131 %x SC_BRACKETED_ID SC_RETURN_BRACKETED_ID
133 letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
134 notletter [^.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]{-}[%\{]
135 id {letter}({letter}|[-0-9])*
138 /* Zero or more instances of backslash-newline. Following GCC, allow
139 white space between the backslash and the newline. */
140 splice (\\[ \f\t\v]*\n)*
142 /* An equal sign, with optional leading whitespaces. This is used in some
143 deprecated constructs. */
144 eqopt ([[:space:]]*=)?
148 /* Nesting level. Either for nested braces, or nested angle brackets
150 int nesting PACIFY_CC (= 0);
152 /* Parent context state, when applicable. */
153 int context_state PACIFY_CC (= 0);
155 /* Location of most recent identifier, when applicable. */
156 location id_loc PACIFY_CC (= empty_location);
158 /* Where containing code started, when applicable. Its initial
159 value is relevant only when yylex is invoked in the SC_EPILOGUE
161 boundary code_start = scanner_cursor;
163 /* Where containing comment or string or character literal started,
165 boundary token_start PACIFY_CC (= scanner_cursor);
167 /* We cannot trust YY_USER_INIT, whose semantics changes over time
168 (it moved in Flex 2.5.38). */
169 static bool first = true;
172 scanner_cursor = loc->start;
178 /*-----------------------.
179 | Scanning white space. |
180 `-----------------------*/
182 <INITIAL,SC_AFTER_IDENTIFIER,SC_BRACKETED_ID,SC_RETURN_BRACKETED_ID>
184 /* Comments and white space. */
186 complain (loc, Wother, _("stray ',' treated as white space"));
191 token_start = loc->start;
192 context_state = YY_START;
193 BEGIN SC_YACC_COMMENT;
196 /* #line directives are not documented, and may be withdrawn or
197 modified in future versions of Bison. */
198 ^"#line "{int}(" \"".*"\"")?"\n" {
199 handle_syncline (yytext + sizeof "#line " - 1, *loc);
204 /*----------------------------.
205 | Scanning Bison directives. |
206 `----------------------------*/
208 /* For directives that are also command line options, the regex must be
210 after "[-_]"s are removed, and the directive must match the --long
211 option name, with a single string argument. Otherwise, add exceptions
212 to ../build-aux/cross-options.pl. */
216 "%binary" return PERCENT_NONASSOC;
217 "%code" return PERCENT_CODE;
218 "%debug" RETURN_PERCENT_FLAG("parse.trace");
219 "%default-prec" return PERCENT_DEFAULT_PREC;
220 "%define" return PERCENT_DEFINE;
221 "%defines" return PERCENT_DEFINES;
222 "%destructor" return PERCENT_DESTRUCTOR;
223 "%dprec" return PERCENT_DPREC;
224 "%empty" return PERCENT_EMPTY;
225 "%error-verbose" return PERCENT_ERROR_VERBOSE;
226 "%expect" return PERCENT_EXPECT;
227 "%expect-rr" return PERCENT_EXPECT_RR;
228 "%file-prefix" return PERCENT_FILE_PREFIX;
229 "%fixed-output-files" return PERCENT_YACC;
230 "%initial-action" return PERCENT_INITIAL_ACTION;
231 "%glr-parser" return PERCENT_GLR_PARSER;
232 "%language" return PERCENT_LANGUAGE;
233 "%left" return PERCENT_LEFT;
234 "%lex-param" RETURN_PERCENT_PARAM(lex);
235 "%locations" RETURN_PERCENT_FLAG("locations");
236 "%merge" return PERCENT_MERGE;
237 "%name-prefix" return PERCENT_NAME_PREFIX;
238 "%no-default-prec" return PERCENT_NO_DEFAULT_PREC;
239 "%no-lines" return PERCENT_NO_LINES;
240 "%nonassoc" return PERCENT_NONASSOC;
241 "%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER;
242 "%nterm" return PERCENT_NTERM;
243 "%output" return PERCENT_OUTPUT;
244 "%param" RETURN_PERCENT_PARAM(both);
245 "%parse-param" RETURN_PERCENT_PARAM(parse);
246 "%prec" return PERCENT_PREC;
247 "%precedence" return PERCENT_PRECEDENCE;
248 "%printer" return PERCENT_PRINTER;
249 "%pure-parser" RETURN_PERCENT_FLAG("api.pure");
250 "%require" return PERCENT_REQUIRE;
251 "%right" return PERCENT_RIGHT;
252 "%skeleton" return PERCENT_SKELETON;
253 "%start" return PERCENT_START;
254 "%term" return PERCENT_TOKEN;
255 "%token" return PERCENT_TOKEN;
256 "%token-table" return PERCENT_TOKEN_TABLE;
257 "%type" return PERCENT_TYPE;
258 "%union" return PERCENT_UNION;
259 "%verbose" return PERCENT_VERBOSE;
260 "%yacc" return PERCENT_YACC;
263 "%default"[-_]"prec" DEPRECATED("%default-prec");
264 "%error"[-_]"verbose" DEPRECATED("%define parse.error verbose");
265 "%expect"[-_]"rr" DEPRECATED("%expect-rr");
266 "%file-prefix"{eqopt} DEPRECATED("%file-prefix");
267 "%fixed"[-_]"output"[-_]"files" DEPRECATED("%fixed-output-files");
268 "%name"[-_]"prefix"{eqopt} DEPRECATED("%name-prefix");
269 "%no"[-_]"default"[-_]"prec" DEPRECATED("%no-default-prec");
270 "%no"[-_]"lines" DEPRECATED("%no-lines");
271 "%output"{eqopt} DEPRECATED("%output");
272 "%pure"[-_]"parser" DEPRECATED("%pure-parser");
273 "%token"[-_]"table" DEPRECATED("%token-table");
276 complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
281 ";" return SEMICOLON;
284 val->uniqstr = uniqstr_new (yytext);
286 bracketed_id_str = NULL;
287 BEGIN SC_AFTER_IDENTIFIER;
291 val->integer = scan_integer (yytext, 10, *loc);
294 0[xX][0-9abcdefABCDEF]+ {
295 val->integer = scan_integer (yytext, 16, *loc);
299 /* Identifiers may not start with a digit. Yet, don't silently
300 accept "1FOO" as "1 FOO". */
302 complain (loc, complaint, _("invalid identifier: %s"), quote (yytext));
306 "'" token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
309 "\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
312 "%{" code_start = loc->start; BEGIN SC_PROLOGUE;
314 /* Code in between braces. */
318 code_start = loc->start;
319 BEGIN SC_BRACED_CODE;
322 /* Semantic predicate. */
323 "%?"[ \f\n\t\v]*"{" {
325 code_start = loc->start;
330 "<*>" return TAG_ANY;
331 "<>" return TAG_NONE;
334 token_start = loc->start;
339 static int percent_percent_count;
340 if (++percent_percent_count == 2)
342 return PERCENT_PERCENT;
346 bracketed_id_str = NULL;
347 bracketed_id_start = loc->start;
348 bracketed_id_context_state = YY_START;
349 BEGIN SC_BRACKETED_ID;
352 [^\[%A-Za-z0-9_<>{}\"\'*;|=/, \f\n\t\v]+|. {
353 complain (loc, complaint, "%s: %s",
354 ngettext ("invalid character", "invalid characters", yyleng),
355 quote_mem (yytext, yyleng));
359 loc->start = loc->end = scanner_cursor;
365 /*--------------------------------------------------------------.
366 | Supporting \0 complexifies our implementation for no expected |
368 `--------------------------------------------------------------*/
370 <SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_TAG>
372 \0 complain (loc, complaint, _("invalid null character"));
376 /*-----------------------------------------------------------------.
377 | Scanning after an identifier, checking whether a colon is next. |
378 `-----------------------------------------------------------------*/
380 <SC_AFTER_IDENTIFIER>
383 if (bracketed_id_str)
385 ROLLBACK_CURRENT_TOKEN;
386 BEGIN SC_RETURN_BRACKETED_ID;
392 bracketed_id_start = loc->start;
393 bracketed_id_context_state = YY_START;
394 BEGIN SC_BRACKETED_ID;
398 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
403 ROLLBACK_CURRENT_TOKEN;
404 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
409 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
415 /*--------------------------------.
416 | Scanning bracketed identifiers. |
417 `--------------------------------*/
422 if (bracketed_id_str)
424 complain (loc, complaint,
425 _("unexpected identifier in bracketed name: %s"),
430 bracketed_id_str = uniqstr_new (yytext);
431 bracketed_id_loc = *loc;
435 BEGIN bracketed_id_context_state;
436 if (bracketed_id_str)
438 if (INITIAL == bracketed_id_context_state)
440 val->uniqstr = bracketed_id_str;
441 bracketed_id_str = 0;
442 *loc = bracketed_id_loc;
447 complain (loc, complaint, _("an identifier expected"));
450 [^\].A-Za-z0-9_/ \f\n\t\v]+|. {
451 complain (loc, complaint, "%s: %s",
452 ngettext ("invalid character in bracketed name",
453 "invalid characters in bracketed name", yyleng),
454 quote_mem (yytext, yyleng));
458 BEGIN bracketed_id_context_state;
459 unexpected_eof (bracketed_id_start, "]");
463 <SC_RETURN_BRACKETED_ID>
466 ROLLBACK_CURRENT_TOKEN;
467 val->uniqstr = bracketed_id_str;
468 bracketed_id_str = 0;
469 *loc = bracketed_id_loc;
476 /*---------------------------------------------------------------.
477 | Scanning a Yacc comment. The initial '/ *' is already eaten. |
478 `---------------------------------------------------------------*/
482 "*/" BEGIN context_state;
484 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
488 /*------------------------------------------------------------.
489 | Scanning a C comment. The initial '/ *' is already eaten. |
490 `------------------------------------------------------------*/
494 "*"{splice}"/" STRING_GROW; BEGIN context_state;
495 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
499 /*--------------------------------------------------------------.
500 | Scanning a line comment. The initial '//' is already eaten. |
501 `--------------------------------------------------------------*/
505 "\n" STRING_GROW; BEGIN context_state;
506 {splice} STRING_GROW;
507 <<EOF>> BEGIN context_state;
511 /*------------------------------------------------.
512 | Scanning a Bison string, including its escapes. |
513 | The initial quote is already eaten. |
514 `------------------------------------------------*/
520 loc->start = token_start;
521 val->code = last_string;
525 <<EOF>> unexpected_eof (token_start, "\"");
526 "\n" unexpected_newline (token_start, "\"");
529 /*----------------------------------------------------------.
530 | Scanning a Bison character literal, decoding its escapes. |
531 | The initial quote is already eaten. |
532 `----------------------------------------------------------*/
534 <SC_ESCAPED_CHARACTER>
538 loc->start = token_start;
539 val->character = last_string[0];
541 /* FIXME: Eventually, make these errors. */
542 if (last_string[0] == '\0')
544 complain (loc, Wother, _("empty character literal"));
545 /* '\0' seems dangerous even if we are about to complain. */
546 val->character = '\'';
548 else if (last_string[1] != '\0')
549 complain (loc, Wother,
550 _("extra characters in character literal"));
555 "\n" unexpected_newline (token_start, "'");
556 <<EOF>> unexpected_eof (token_start, "'");
561 /*--------------------------------------------------------------.
562 | Scanning a tag. The initial angle bracket is already eaten. |
563 `--------------------------------------------------------------*/
572 loc->start = token_start;
573 val->uniqstr = uniqstr_new (last_string);
581 ([^<>]|->)+ STRING_GROW;
582 "<"+ STRING_GROW; nesting += yyleng;
584 <<EOF>> unexpected_eof (token_start, ">");
587 /*----------------------------.
588 | Decode escaped characters. |
589 `----------------------------*/
591 <SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
594 unsigned long int c = strtoul (yytext + 1, NULL, 8);
595 if (!c || UCHAR_MAX < c)
596 complain (loc, complaint, _("invalid number after \\-escape: %s"),
599 obstack_1grow (&obstack_for_string, c);
602 \\x[0-9abcdefABCDEF]+ {
603 verify (UCHAR_MAX < ULONG_MAX);
604 unsigned long int c = strtoul (yytext + 2, NULL, 16);
605 if (!c || UCHAR_MAX < c)
606 complain (loc, complaint, _("invalid number after \\-escape: %s"),
609 obstack_1grow (&obstack_for_string, c);
612 \\a obstack_1grow (&obstack_for_string, '\a');
613 \\b obstack_1grow (&obstack_for_string, '\b');
614 \\f obstack_1grow (&obstack_for_string, '\f');
615 \\n obstack_1grow (&obstack_for_string, '\n');
616 \\r obstack_1grow (&obstack_for_string, '\r');
617 \\t obstack_1grow (&obstack_for_string, '\t');
618 \\v obstack_1grow (&obstack_for_string, '\v');
620 /* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
621 \\("\""|"'"|"?"|"\\") obstack_1grow (&obstack_for_string, yytext[1]);
623 \\(u|U[0-9abcdefABCDEF]{4})[0-9abcdefABCDEF]{4} {
624 int c = convert_ucn_to_byte (yytext);
626 complain (loc, complaint, _("invalid number after \\-escape: %s"),
629 obstack_1grow (&obstack_for_string, c);
632 char const *p = yytext + 1;
633 /* Quote only if escaping won't make the character visible. */
634 if (c_isspace ((unsigned char) *p) && c_isprint ((unsigned char) *p))
637 p = quotearg_style_mem (escape_quoting_style, p, 1);
638 complain (loc, complaint, _("invalid character after \\-escape: %s"),
643 /*--------------------------------------------.
644 | Scanning user-code characters and strings. |
645 `--------------------------------------------*/
647 <SC_CHARACTER,SC_STRING>
649 {splice}|\\{splice}[^\n\[\]] STRING_GROW;
654 "'" STRING_GROW; BEGIN context_state;
655 \n unexpected_newline (token_start, "'");
656 <<EOF>> unexpected_eof (token_start, "'");
661 "\"" STRING_GROW; BEGIN context_state;
662 \n unexpected_newline (token_start, "\"");
663 <<EOF>> unexpected_eof (token_start, "\"");
667 /*---------------------------------------------------.
668 | Strings, comments etc. can be found in user code. |
669 `---------------------------------------------------*/
671 <SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE,SC_PREDICATE>
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 token_start = loc->start;
693 context_state = YY_START;
694 BEGIN SC_LINE_COMMENT;
700 /*-----------------------------------------------------------.
701 | Scanning some code in braces (actions, predicates). The |
702 | initial "{" is already eaten. |
703 `-----------------------------------------------------------*/
705 <SC_BRACED_CODE,SC_PREDICATE>
707 "{"|"<"{splice}"%" STRING_GROW; nesting++;
708 "%"{splice}">" STRING_GROW; nesting--;
710 /* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly
712 "<"{splice}"<" STRING_GROW;
714 <<EOF>> unexpected_eof (code_start, "}");
720 obstack_1grow (&obstack_for_string, '}');
726 loc->start = code_start;
727 val->code = last_string;
741 loc->start = code_start;
742 val->code = last_string;
744 return BRACED_PREDICATE;
747 obstack_1grow (&obstack_for_string, '}');
751 /*--------------------------------------------------------------.
752 | Scanning some prologue: from "%{" (already scanned) to "%}". |
753 `--------------------------------------------------------------*/
759 loc->start = code_start;
760 val->code = last_string;
765 <<EOF>> unexpected_eof (code_start, "%}");
769 /*---------------------------------------------------------------.
770 | Scanning the epilogue (everything after the second "%%", which |
771 | has already been eaten). |
772 `---------------------------------------------------------------*/
778 loc->start = code_start;
779 val->code = last_string;
786 /*-----------------------------------------------------.
787 | By default, grow the string obstack with the input. |
788 `-----------------------------------------------------*/
790 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>. |
791 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE>\n STRING_GROW;
795 /* Read bytes from FP into buffer BUF of size SIZE. Return the
796 number of bytes read. Remove '\r' from input, treating \r\n
797 and isolated \r as \n. */
800 no_cr_read (FILE *fp, char *buf, size_t size)
802 size_t bytes_read = fread (buf, 1, size, fp);
805 char *w = memchr (buf, '\r', bytes_read);
809 char const *lim = buf + bytes_read;
813 /* Found an '\r'. Treat it like '\n', but ignore any
814 '\n' that immediately follows. */
819 if (ch != '\n' && ungetc (ch, fp) != ch)
825 /* Copy until the next '\r'. */
831 while ((*w++ = *r++) != '\r');
843 /*------------------------------------------------------.
844 | Scan NUMBER for a base-BASE integer at location LOC. |
845 `------------------------------------------------------*/
847 static unsigned long int
848 scan_integer (char const *number, int base, location loc)
850 verify (INT_MAX < ULONG_MAX);
851 unsigned long int num = strtoul (number, NULL, base);
855 complain (&loc, complaint, _("integer out of range: %s"),
864 /*------------------------------------------------------------------.
865 | Convert universal character name UCN to a single-byte character, |
866 | and return that character. Return -1 if UCN does not correspond |
867 | to a single-byte character. |
868 `------------------------------------------------------------------*/
871 convert_ucn_to_byte (char const *ucn)
873 verify (UCHAR_MAX <= INT_MAX);
874 unsigned long int code = strtoul (ucn + 2, NULL, 16);
876 /* FIXME: Currently we assume Unicode-compatible unibyte characters
877 on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
878 non-ASCII hosts we support only the portable C character set.
879 These limitations should be removed once we add support for
880 multibyte characters. */
882 if (UCHAR_MAX < code)
885 #if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
887 /* A non-ASCII host. Use CODE to index into a table of the C
888 basic execution character set, which is guaranteed to exist on
889 all Standard C platforms. This table also includes '$', '@',
890 and '`', which are not in the basic execution character set but
891 which are unibyte characters on all the platforms that we know
893 static signed char const table[] =
895 '\0', -1, -1, -1, -1, -1, -1, '\a',
896 '\b', '\t', '\n', '\v', '\f', '\r', -1, -1,
897 -1, -1, -1, -1, -1, -1, -1, -1,
898 -1, -1, -1, -1, -1, -1, -1, -1,
899 ' ', '!', '"', '#', '$', '%', '&', '\'',
900 '(', ')', '*', '+', ',', '-', '.', '/',
901 '0', '1', '2', '3', '4', '5', '6', '7',
902 '8', '9', ':', ';', '<', '=', '>', '?',
903 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
904 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
905 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
906 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
907 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
908 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
909 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
910 'x', 'y', 'z', '{', '|', '}', '~'
913 code = code < sizeof table ? table[code] : -1;
921 /*---------------------------------------------------------------------.
922 | Handle '#line INT( "FILE")?\n'. ARGS has already skipped '#line '. |
923 `---------------------------------------------------------------------*/
926 handle_syncline (char *args, location loc)
929 unsigned long int lineno = strtoul (args, &file, 10);
930 if (INT_MAX <= lineno)
932 complain (&loc, Wother, _("line number overflow"));
936 file = strchr (file, '"');
939 *strchr (file + 1, '"') = '\0';
940 current_file = uniqstr_new (file + 1);
942 boundary_set (&scanner_cursor, current_file, lineno, 1);
946 /*----------------------------------------------------------------.
947 | For a token or comment starting at START, report message MSGID, |
948 | which should say that an end marker was found before the |
949 | expected TOKEN_END. Then, pretend that TOKEN_END was found. |
950 `----------------------------------------------------------------*/
953 unexpected_end (boundary start, char const *msgid, char const *token_end)
957 loc.end = scanner_cursor;
958 size_t i = strlen (token_end);
960 /* Adjust scanner cursor so that any later message does not count
961 the characters about to be inserted. */
962 scanner_cursor.column -= i;
965 unput (token_end[--i]);
967 token_end = quote (token_end);
968 /* Instead of '\'', display "'". */
969 if (STREQ (token_end, "'\\''"))
971 complain (&loc, complaint, _(msgid), token_end);
975 /*------------------------------------------------------------------------.
976 | Report an unexpected EOF in a token or comment starting at START. |
977 | An end of file was encountered and the expected TOKEN_END was missing. |
978 | After reporting the problem, pretend that TOKEN_END was found. |
979 `------------------------------------------------------------------------*/
982 unexpected_eof (boundary start, char const *token_end)
984 unexpected_end (start, N_("missing %s at end of file"), token_end);
988 /*----------------------------------------.
989 | Likewise, but for unexpected newlines. |
990 `----------------------------------------*/
993 unexpected_newline (boundary start, char const *token_end)
995 unexpected_end (start, N_("missing %s at end of line"), token_end);
999 /*-------------------------.
1000 | Initialize the scanner. |
1001 `-------------------------*/
1004 gram_scanner_initialize (void)
1006 obstack_init (&obstack_for_string);
1010 /*-----------------------------------------------.
1011 | Free all the memory allocated to the scanner. |
1012 `-----------------------------------------------*/
1015 gram_scanner_free (void)
1017 obstack_free (&obstack_for_string, 0);
1018 /* Reclaim Flex's buffers. */