1 /* Bison Grammar Scanner -*- C -*-
3 Copyright (C) 2002-2012 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 complain (loc, Wdeprecated, \
81 _("deprecated directive: %s, use %s"), \
82 quote (yytext), quote_n (1, Msg)); \
83 scanner_cursor.column -= mbsnwidth (Msg, strlen (Msg), 0); \
84 for (i = strlen (Msg); i != 0; --i) \
88 /* A string representing the most recently saved token. */
89 static char *last_string;
91 /* Bracketed identifier. */
92 static uniqstr bracketed_id_str = 0;
93 static location bracketed_id_loc;
94 static boundary bracketed_id_start;
95 static int bracketed_id_context_state = 0;
98 gram_scanner_last_string_free (void)
103 static void handle_syncline (char *, location);
104 static unsigned long int scan_integer (char const *p, int base, location loc);
105 static int convert_ucn_to_byte (char const *hex_text);
106 static void unexpected_eof (boundary, char const *);
107 static void unexpected_newline (boundary, char const *);
110 /* A C-like comment in directives/rules. */
112 /* Strings and characters in directives/rules. */
113 %x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
114 /* A identifier was just read in directives/rules. Special state
115 to capture the sequence 'identifier :'. */
116 %x SC_AFTER_IDENTIFIER
117 /* A complex tag, with nested angles brackets. */
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 /* POSIX says that a tag must be both an id and a C union member, but
139 historically almost any character is allowed in a tag. We disallow
140 NUL, as this simplifies our implementation. We disallow angle
141 bracket to match them in nested pairs: several languages use them
142 for generics/template types. */
145 /* Zero or more instances of backslash-newline. Following GCC, allow
146 white space between the backslash and the newline. */
147 splice (\\[ \f\t\v]*\n)*
149 /* An equal sign, with optional leading whitespaces. This is used in some
150 deprecated constructs. */
151 eqopt ([[:space:]]*=)?
155 /* Nesting level. Either for nested braces, or nested angle brackets
157 int nesting PACIFY_CC (= 0);
159 /* Parent context state, when applicable. */
160 int context_state PACIFY_CC (= 0);
162 /* Location of most recent identifier, when applicable. */
163 location id_loc PACIFY_CC (= empty_location);
165 /* Where containing code started, when applicable. Its initial
166 value is relevant only when yylex is invoked in the SC_EPILOGUE
168 boundary code_start = scanner_cursor;
170 /* Where containing comment or string or character literal started,
172 boundary token_start PACIFY_CC (= scanner_cursor);
176 /*-----------------------.
177 | Scanning white space. |
178 `-----------------------*/
180 <INITIAL,SC_AFTER_IDENTIFIER,SC_BRACKETED_ID,SC_RETURN_BRACKETED_ID>
182 /* Comments and white space. */
184 complain (loc, Wother, _("stray ',' treated as white space"));
189 token_start = loc->start;
190 context_state = YY_START;
191 BEGIN SC_YACC_COMMENT;
194 /* #line directives are not documented, and may be withdrawn or
195 modified in future versions of Bison. */
196 ^"#line "{int}" \"".*"\"\n" {
197 handle_syncline (yytext + sizeof "#line " - 1, *loc);
202 /*----------------------------.
203 | Scanning Bison directives. |
204 `----------------------------*/
206 /* For directives that are also command line options, the regex must be
208 after "[-_]"s are removed, and the directive must match the --long
209 option name, with a single string argument. Otherwise, add exceptions
210 to ../build-aux/cross-options.pl. */
214 "%binary" return PERCENT_NONASSOC;
215 "%code" return PERCENT_CODE;
216 "%debug" RETURN_PERCENT_FLAG("parse.trace");
217 "%default-prec" return PERCENT_DEFAULT_PREC;
218 "%define" return PERCENT_DEFINE;
219 "%defines" return PERCENT_DEFINES;
220 "%destructor" return PERCENT_DESTRUCTOR;
221 "%dprec" return PERCENT_DPREC;
222 "%error-verbose" return PERCENT_ERROR_VERBOSE;
223 "%expect" return PERCENT_EXPECT;
224 "%expect-rr" return PERCENT_EXPECT_RR;
225 "%file-prefix" return PERCENT_FILE_PREFIX;
226 "%fixed-output-files" return PERCENT_YACC;
227 "%initial-action" return PERCENT_INITIAL_ACTION;
228 "%glr-parser" return PERCENT_GLR_PARSER;
229 "%language" return PERCENT_LANGUAGE;
230 "%left" return PERCENT_LEFT;
231 "%lex-param" RETURN_PERCENT_PARAM(lex);
232 "%locations" RETURN_PERCENT_FLAG("locations");
233 "%merge" return PERCENT_MERGE;
234 "%name-prefix" return PERCENT_NAME_PREFIX;
235 "%no-default-prec" return PERCENT_NO_DEFAULT_PREC;
236 "%no-lines" return PERCENT_NO_LINES;
237 "%nonassoc" return PERCENT_NONASSOC;
238 "%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER;
239 "%nterm" return PERCENT_NTERM;
240 "%output" return PERCENT_OUTPUT;
241 "%param" RETURN_PERCENT_PARAM(both);
242 "%parse-param" RETURN_PERCENT_PARAM(parse);
243 "%prec" return PERCENT_PREC;
244 "%precedence" return PERCENT_PRECEDENCE;
245 "%printer" return PERCENT_PRINTER;
246 "%pure-parser" RETURN_PERCENT_FLAG("api.pure");
247 "%require" return PERCENT_REQUIRE;
248 "%right" return PERCENT_RIGHT;
249 "%skeleton" return PERCENT_SKELETON;
250 "%start" return PERCENT_START;
251 "%term" return PERCENT_TOKEN;
252 "%token" return PERCENT_TOKEN;
253 "%token-table" return PERCENT_TOKEN_TABLE;
254 "%type" return PERCENT_TYPE;
255 "%union" return PERCENT_UNION;
256 "%verbose" return PERCENT_VERBOSE;
257 "%yacc" return PERCENT_YACC;
260 "%default"[-_]"prec" DEPRECATED("%default-prec");
261 "%error"[-_]"verbose" DEPRECATED("%define parse.error verbose");
262 "%expect"[-_]"rr" DEPRECATED("%expect-rr");
263 "%file-prefix"{eqopt} DEPRECATED("%file-prefix");
264 "%fixed"[-_]"output"[-_]"files" DEPRECATED("%fixed-output-files");
265 "%name"[-_]"prefix"{eqopt} DEPRECATED("%name-prefix");
266 "%no"[-_]"default"[-_]"prec" DEPRECATED("%no-default-prec");
267 "%no"[-_]"lines" DEPRECATED("%no-lines");
268 "%output"{eqopt} DEPRECATED("%output");
269 "%pure"[-_]"parser" DEPRECATED("%pure-parser");
270 "%token"[-_]"table" DEPRECATED("%token-table");
272 "%"{id}|"%"{notletter}([[:graph:]])+ {
273 complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
278 ";" return SEMICOLON;
281 val->uniqstr = uniqstr_new (yytext);
283 bracketed_id_str = NULL;
284 BEGIN SC_AFTER_IDENTIFIER;
288 val->integer = scan_integer (yytext, 10, *loc);
291 0[xX][0-9abcdefABCDEF]+ {
292 val->integer = scan_integer (yytext, 16, *loc);
296 /* Identifiers may not start with a digit. Yet, don't silently
297 accept "1FOO" as "1 FOO". */
299 complain (loc, complaint, _("invalid identifier: %s"), quote (yytext));
303 "'" token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
306 "\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
309 "%{" code_start = loc->start; BEGIN SC_PROLOGUE;
311 /* Code in between braces. */
315 code_start = loc->start;
316 BEGIN SC_BRACED_CODE;
319 /* Semantic predicate. */
320 "%?"[ \f\n\t\v]*"{" {
322 code_start = loc->start;
327 "<*>" return TAG_ANY;
328 "<>" return TAG_NONE;
330 obstack_grow (&obstack_for_string, yytext + 1, yyleng - 2);
332 val->uniqstr = uniqstr_new (last_string);
338 token_start = loc->start;
343 static int percent_percent_count;
344 if (++percent_percent_count == 2)
346 return PERCENT_PERCENT;
350 bracketed_id_str = NULL;
351 bracketed_id_start = loc->start;
352 bracketed_id_context_state = YY_START;
353 BEGIN SC_BRACKETED_ID;
356 [^\[%A-Za-z0-9_<>{}\"\'*;|=/, \f\n\t\v]+|. {
357 complain (loc, complaint, "%s: %s",
358 ngettext ("invalid character", "invalid characters", yyleng),
359 quote_mem (yytext, yyleng));
363 loc->start = loc->end = scanner_cursor;
369 /*--------------------------------------------------------------.
370 | Supporting \0 complexifies our implementation for no expected |
372 `--------------------------------------------------------------*/
374 <SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_TAG>
376 \0 complain (loc, complaint, _("invalid null character"));
380 /*-----------------------------------------------------------------.
381 | Scanning after an identifier, checking whether a colon is next. |
382 `-----------------------------------------------------------------*/
384 <SC_AFTER_IDENTIFIER>
387 if (bracketed_id_str)
389 ROLLBACK_CURRENT_TOKEN;
390 BEGIN SC_RETURN_BRACKETED_ID;
396 bracketed_id_start = loc->start;
397 bracketed_id_context_state = YY_START;
398 BEGIN SC_BRACKETED_ID;
402 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
407 ROLLBACK_CURRENT_TOKEN;
408 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
413 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
419 /*--------------------------------.
420 | Scanning bracketed identifiers. |
421 `--------------------------------*/
426 if (bracketed_id_str)
428 complain (loc, complaint,
429 _("unexpected identifier in bracketed name: %s"),
434 bracketed_id_str = uniqstr_new (yytext);
435 bracketed_id_loc = *loc;
439 BEGIN bracketed_id_context_state;
440 if (bracketed_id_str)
442 if (INITIAL == bracketed_id_context_state)
444 val->uniqstr = bracketed_id_str;
445 bracketed_id_str = 0;
446 *loc = bracketed_id_loc;
451 complain (loc, complaint, _("an identifier expected"));
454 [^\].A-Za-z0-9_/ \f\n\t\v]+|. {
455 complain (loc, complaint, "%s: %s",
456 ngettext ("invalid character in bracketed name",
457 "invalid characters in bracketed name", yyleng),
458 quote_mem (yytext, yyleng));
462 BEGIN bracketed_id_context_state;
463 unexpected_eof (bracketed_id_start, "]");
467 <SC_RETURN_BRACKETED_ID>
470 ROLLBACK_CURRENT_TOKEN;
471 val->uniqstr = bracketed_id_str;
472 bracketed_id_str = 0;
473 *loc = bracketed_id_loc;
480 /*---------------------------------------------------------------.
481 | Scanning a Yacc comment. The initial '/ *' is already eaten. |
482 `---------------------------------------------------------------*/
486 "*/" BEGIN context_state;
488 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
492 /*------------------------------------------------------------.
493 | Scanning a C comment. The initial '/ *' is already eaten. |
494 `------------------------------------------------------------*/
498 "*"{splice}"/" STRING_GROW; BEGIN context_state;
499 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
503 /*--------------------------------------------------------------.
504 | Scanning a line comment. The initial '//' is already eaten. |
505 `--------------------------------------------------------------*/
509 "\n" STRING_GROW; BEGIN context_state;
510 {splice} STRING_GROW;
511 <<EOF>> BEGIN context_state;
515 /*------------------------------------------------.
516 | Scanning a Bison string, including its escapes. |
517 | The initial quote is already eaten. |
518 `------------------------------------------------*/
523 if (yytext[0] == '\n')
524 unexpected_newline (token_start, "\"");
526 loc->start = token_start;
527 val->chars = last_string;
532 unexpected_eof (token_start, "\"");
534 loc->start = token_start;
535 val->chars = last_string;
541 /*----------------------------------------------------------.
542 | Scanning a Bison character literal, decoding its escapes. |
543 | The initial quote is already eaten. |
544 `----------------------------------------------------------*/
546 <SC_ESCAPED_CHARACTER>
550 loc->start = token_start;
551 val->character = last_string[0];
553 /* FIXME: Eventually, make these errors. */
554 if (last_string[0] == '\0')
556 complain (loc, Wother, _("empty character literal"));
557 /* '\0' seems dangerous even if we are about to complain. */
558 val->character = '\'';
560 else if (last_string[1] != '\0')
561 complain (loc, Wother,
562 _("extra characters in character literal"));
564 if (yytext[0] == '\n')
565 unexpected_newline (token_start, "'");
572 loc->start = token_start;
573 val->character = last_string[0];
575 /* FIXME: Eventually, make these errors. */
576 if (last_string[0] == '\0')
578 complain (loc, Wother, _("empty character literal"));
579 /* '\0' seems dangerous even if we are about to complain. */
580 val->character = '\'';
582 else if (last_string[1] != '\0')
583 complain (loc, Wother,
584 _("extra characters in character literal"));
586 unexpected_eof (token_start, "'");
593 /*-----------------------------------------------------------.
594 | Scanning a Bison nested tag. The initial angle bracket is |
596 `-----------------------------------------------------------*/
605 loc->start = token_start;
606 val->uniqstr = uniqstr_new (last_string);
615 "<"+ STRING_GROW; nesting += yyleng;
618 unexpected_eof (token_start, ">");
620 loc->start = token_start;
621 val->uniqstr = uniqstr_new (last_string);
628 /*----------------------------.
629 | Decode escaped characters. |
630 `----------------------------*/
632 <SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
635 unsigned long int c = strtoul (yytext + 1, NULL, 8);
636 if (!c || UCHAR_MAX < c)
637 complain (loc, complaint, _("invalid number after \\-escape: %s"),
640 obstack_1grow (&obstack_for_string, c);
643 \\x[0-9abcdefABCDEF]+ {
644 verify (UCHAR_MAX < ULONG_MAX);
645 unsigned long int c = strtoul (yytext + 2, NULL, 16);
646 if (!c || UCHAR_MAX < c)
647 complain (loc, complaint, _("invalid number after \\-escape: %s"),
650 obstack_1grow (&obstack_for_string, c);
653 \\a obstack_1grow (&obstack_for_string, '\a');
654 \\b obstack_1grow (&obstack_for_string, '\b');
655 \\f obstack_1grow (&obstack_for_string, '\f');
656 \\n obstack_1grow (&obstack_for_string, '\n');
657 \\r obstack_1grow (&obstack_for_string, '\r');
658 \\t obstack_1grow (&obstack_for_string, '\t');
659 \\v obstack_1grow (&obstack_for_string, '\v');
661 /* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
662 \\("\""|"'"|"?"|"\\") obstack_1grow (&obstack_for_string, yytext[1]);
664 \\(u|U[0-9abcdefABCDEF]{4})[0-9abcdefABCDEF]{4} {
665 int c = convert_ucn_to_byte (yytext);
667 complain (loc, complaint, _("invalid number after \\-escape: %s"),
670 obstack_1grow (&obstack_for_string, c);
673 char const *p = yytext + 1;
674 /* Quote only if escaping won't make the character visible. */
675 if (c_isspace ((unsigned char) *p) && c_isprint ((unsigned char) *p))
678 p = quotearg_style_mem (escape_quoting_style, p, 1);
679 complain (loc, complaint, _("invalid character after \\-escape: %s"),
684 /*--------------------------------------------.
685 | Scanning user-code characters and strings. |
686 `--------------------------------------------*/
688 <SC_CHARACTER,SC_STRING>
690 {splice}|\\{splice}[^\n\[\]] STRING_GROW;
695 "'" STRING_GROW; BEGIN context_state;
696 \n unexpected_newline (token_start, "'"); BEGIN context_state;
697 <<EOF>> unexpected_eof (token_start, "'"); BEGIN context_state;
702 "\"" STRING_GROW; BEGIN context_state;
703 \n unexpected_newline (token_start, "\""); BEGIN context_state;
704 <<EOF>> unexpected_eof (token_start, "\""); BEGIN context_state;
708 /*---------------------------------------------------.
709 | Strings, comments etc. can be found in user code. |
710 `---------------------------------------------------*/
712 <SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE,SC_PREDICATE>
716 context_state = YY_START;
717 token_start = loc->start;
722 context_state = YY_START;
723 token_start = loc->start;
728 context_state = YY_START;
729 token_start = loc->start;
734 context_state = YY_START;
735 BEGIN SC_LINE_COMMENT;
741 /*-----------------------------------------------------------.
742 | Scanning some code in braces (actions, predicates). The |
743 | initial "{" is already eaten. |
744 `-----------------------------------------------------------*/
746 <SC_BRACED_CODE,SC_PREDICATE>
748 "{"|"<"{splice}"%" STRING_GROW; nesting++;
749 "%"{splice}">" STRING_GROW; nesting--;
751 /* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly
753 "<"{splice}"<" STRING_GROW;
756 int token = (YY_START == SC_BRACED_CODE) ? BRACED_CODE : BRACED_PREDICATE;
757 unexpected_eof (code_start, "}");
759 loc->start = code_start;
760 val->code = last_string;
769 obstack_1grow (&obstack_for_string, '}');
775 loc->start = code_start;
776 val->code = last_string;
790 loc->start = code_start;
791 val->code = last_string;
793 return BRACED_PREDICATE;
796 obstack_1grow (&obstack_for_string, '}');
800 /*--------------------------------------------------------------.
801 | Scanning some prologue: from "%{" (already scanned) to "%}". |
802 `--------------------------------------------------------------*/
808 loc->start = code_start;
809 val->chars = last_string;
815 unexpected_eof (code_start, "%}");
817 loc->start = code_start;
818 val->chars = last_string;
825 /*---------------------------------------------------------------.
826 | Scanning the epilogue (everything after the second "%%", which |
827 | has already been eaten). |
828 `---------------------------------------------------------------*/
834 loc->start = code_start;
835 val->chars = last_string;
842 /*-----------------------------------------------------.
843 | By default, grow the string obstack with the input. |
844 `-----------------------------------------------------*/
846 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>. |
847 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE>\n STRING_GROW;
851 /* Read bytes from FP into buffer BUF of size SIZE. Return the
852 number of bytes read. Remove '\r' from input, treating \r\n
853 and isolated \r as \n. */
856 no_cr_read (FILE *fp, char *buf, size_t size)
858 size_t bytes_read = fread (buf, 1, size, fp);
861 char *w = memchr (buf, '\r', bytes_read);
865 char const *lim = buf + bytes_read;
869 /* Found an '\r'. Treat it like '\n', but ignore any
870 '\n' that immediately follows. */
875 if (ch != '\n' && ungetc (ch, fp) != ch)
881 /* Copy until the next '\r'. */
887 while ((*w++ = *r++) != '\r');
899 /*------------------------------------------------------.
900 | Scan NUMBER for a base-BASE integer at location LOC. |
901 `------------------------------------------------------*/
903 static unsigned long int
904 scan_integer (char const *number, int base, location loc)
906 verify (INT_MAX < ULONG_MAX);
907 unsigned long int num = strtoul (number, NULL, base);
911 complain (&loc, complaint, _("integer out of range: %s"),
920 /*------------------------------------------------------------------.
921 | Convert universal character name UCN to a single-byte character, |
922 | and return that character. Return -1 if UCN does not correspond |
923 | to a single-byte character. |
924 `------------------------------------------------------------------*/
927 convert_ucn_to_byte (char const *ucn)
929 verify (UCHAR_MAX <= INT_MAX);
930 unsigned long int code = strtoul (ucn + 2, NULL, 16);
932 /* FIXME: Currently we assume Unicode-compatible unibyte characters
933 on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
934 non-ASCII hosts we support only the portable C character set.
935 These limitations should be removed once we add support for
936 multibyte characters. */
938 if (UCHAR_MAX < code)
941 #if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
943 /* A non-ASCII host. Use CODE to index into a table of the C
944 basic execution character set, which is guaranteed to exist on
945 all Standard C platforms. This table also includes '$', '@',
946 and '`', which are not in the basic execution character set but
947 which are unibyte characters on all the platforms that we know
949 static signed char const table[] =
951 '\0', -1, -1, -1, -1, -1, -1, '\a',
952 '\b', '\t', '\n', '\v', '\f', '\r', -1, -1,
953 -1, -1, -1, -1, -1, -1, -1, -1,
954 -1, -1, -1, -1, -1, -1, -1, -1,
955 ' ', '!', '"', '#', '$', '%', '&', '\'',
956 '(', ')', '*', '+', ',', '-', '.', '/',
957 '0', '1', '2', '3', '4', '5', '6', '7',
958 '8', '9', ':', ';', '<', '=', '>', '?',
959 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
960 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
961 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
962 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
963 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
964 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
965 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
966 'x', 'y', 'z', '{', '|', '}', '~'
969 code = code < sizeof table ? table[code] : -1;
977 /*----------------------------------------------------------------.
978 | Handle '#line INT "FILE"'. ARGS has already skipped '#line '. |
979 `----------------------------------------------------------------*/
982 handle_syncline (char *args, location loc)
985 unsigned long int lineno = strtoul (args, &after_num, 10);
986 char *file = strchr (after_num, '"') + 1;
987 *strchr (file, '"') = '\0';
988 if (INT_MAX <= lineno)
990 complain (&loc, Wother, _("line number overflow"));
993 current_file = uniqstr_new (file);
994 boundary_set (&scanner_cursor, current_file, lineno, 1);
998 /*----------------------------------------------------------------.
999 | For a token or comment starting at START, report message MSGID, |
1000 | which should say that an end marker was found before |
1001 | the expected TOKEN_END. |
1002 `----------------------------------------------------------------*/
1005 unexpected_end (boundary start, char const *msgid, char const *token_end)
1009 loc.end = scanner_cursor;
1010 token_end = quote (token_end);
1011 // Instead of '\'', display "'".
1012 if (STREQ (token_end, "'\\''"))
1013 token_end = "\"'\"";
1014 complain (&loc, complaint, _(msgid), token_end);
1018 /*------------------------------------------------------------------------.
1019 | Report an unexpected EOF in a token or comment starting at START. |
1020 | An end of file was encountered and the expected TOKEN_END was missing. |
1021 `------------------------------------------------------------------------*/
1024 unexpected_eof (boundary start, char const *token_end)
1026 unexpected_end (start, N_("missing %s at end of file"), token_end);
1030 /*----------------------------------------.
1031 | Likewise, but for unexpected newlines. |
1032 `----------------------------------------*/
1035 unexpected_newline (boundary start, char const *token_end)
1037 unexpected_end (start, N_("missing %s at end of line"), token_end);
1041 /*-------------------------.
1042 | Initialize the scanner. |
1043 `-------------------------*/
1046 gram_scanner_initialize (void)
1048 obstack_init (&obstack_for_string);
1052 /*-----------------------------------------------.
1053 | Free all the memory allocated to the scanner. |
1054 `-----------------------------------------------*/
1057 gram_scanner_free (void)
1059 obstack_free (&obstack_for_string, 0);
1060 /* Reclaim Flex's buffers. */