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 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
115 /* A complex tag, with nested angles brackets. */
118 /* Four types of user code:
119 - prologue (code between '%{' '%}' in the first section, before %%);
120 - actions, printers, union, etc, (between braced in the middle section);
121 - epilogue (everything after the second %%).
122 - predicate (code between '%?{' and '{' in middle section); */
123 %x SC_PROLOGUE SC_BRACED_CODE SC_EPILOGUE SC_PREDICATE
124 /* C and C++ comments in code. */
125 %x SC_COMMENT SC_LINE_COMMENT
126 /* Strings and characters in code. */
127 %x SC_STRING SC_CHARACTER
128 /* Bracketed identifiers support. */
129 %x SC_BRACKETED_ID SC_RETURN_BRACKETED_ID
131 letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
132 notletter [^.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]{-}[%\{]
133 id {letter}({letter}|[-0-9])*
136 /* POSIX says that a tag must be both an id and a C union member, but
137 historically almost any character is allowed in a tag. We disallow
138 NUL, as this simplifies our implementation. We disallow angle
139 bracket to match them in nested pairs: several languages use them
140 for generics/template types. */
143 /* Zero or more instances of backslash-newline. Following GCC, allow
144 white space between the backslash and the newline. */
145 splice (\\[ \f\t\v]*\n)*
147 /* An equal sign, with optional leading whitespaces. This is used in some
148 deprecated constructs. */
149 eqopt ([[:space:]]*=)?
153 /* Nesting level. Either for nested braces, or nested angle brackets
155 int nesting PACIFY_CC (= 0);
157 /* Parent context state, when applicable. */
158 int context_state PACIFY_CC (= 0);
160 /* Location of most recent identifier, when applicable. */
161 location id_loc PACIFY_CC (= empty_location);
163 /* Where containing code started, when applicable. Its initial
164 value is relevant only when yylex is invoked in the SC_EPILOGUE
166 boundary code_start = scanner_cursor;
168 /* Where containing comment or string or character literal started,
170 boundary token_start PACIFY_CC (= scanner_cursor);
174 /*-----------------------.
175 | Scanning white space. |
176 `-----------------------*/
178 <INITIAL,SC_AFTER_IDENTIFIER,SC_BRACKETED_ID,SC_RETURN_BRACKETED_ID>
180 /* Comments and white space. */
182 complain (loc, Wother, _("stray ',' treated as white space"));
187 token_start = loc->start;
188 context_state = YY_START;
189 BEGIN SC_YACC_COMMENT;
192 /* #line directives are not documented, and may be withdrawn or
193 modified in future versions of Bison. */
194 ^"#line "{int}(" \"".*"\"")?"\n" {
195 handle_syncline (yytext + sizeof "#line " - 1, *loc);
200 /*----------------------------.
201 | Scanning Bison directives. |
202 `----------------------------*/
204 /* For directives that are also command line options, the regex must be
206 after "[-_]"s are removed, and the directive must match the --long
207 option name, with a single string argument. Otherwise, add exceptions
208 to ../build-aux/cross-options.pl. */
212 "%binary" return PERCENT_NONASSOC;
213 "%code" return PERCENT_CODE;
214 "%debug" RETURN_PERCENT_FLAG("parse.trace");
215 "%default-prec" return PERCENT_DEFAULT_PREC;
216 "%define" return PERCENT_DEFINE;
217 "%defines" return PERCENT_DEFINES;
218 "%destructor" return PERCENT_DESTRUCTOR;
219 "%dprec" return PERCENT_DPREC;
220 "%error-verbose" return PERCENT_ERROR_VERBOSE;
221 "%expect" return PERCENT_EXPECT;
222 "%expect-rr" return PERCENT_EXPECT_RR;
223 "%file-prefix" return PERCENT_FILE_PREFIX;
224 "%fixed-output-files" return PERCENT_YACC;
225 "%initial-action" return PERCENT_INITIAL_ACTION;
226 "%glr-parser" return PERCENT_GLR_PARSER;
227 "%language" return PERCENT_LANGUAGE;
228 "%left" return PERCENT_LEFT;
229 "%lex-param" RETURN_PERCENT_PARAM(lex);
230 "%locations" RETURN_PERCENT_FLAG("locations");
231 "%merge" return PERCENT_MERGE;
232 "%name-prefix" return PERCENT_NAME_PREFIX;
233 "%no-default-prec" return PERCENT_NO_DEFAULT_PREC;
234 "%no-lines" return PERCENT_NO_LINES;
235 "%nonassoc" return PERCENT_NONASSOC;
236 "%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER;
237 "%nterm" return PERCENT_NTERM;
238 "%output" return PERCENT_OUTPUT;
239 "%param" RETURN_PERCENT_PARAM(both);
240 "%parse-param" RETURN_PERCENT_PARAM(parse);
241 "%prec" return PERCENT_PREC;
242 "%precedence" return PERCENT_PRECEDENCE;
243 "%printer" return PERCENT_PRINTER;
244 "%pure-parser" RETURN_PERCENT_FLAG("api.pure");
245 "%require" return PERCENT_REQUIRE;
246 "%right" return PERCENT_RIGHT;
247 "%skeleton" return PERCENT_SKELETON;
248 "%start" return PERCENT_START;
249 "%term" return PERCENT_TOKEN;
250 "%token" return PERCENT_TOKEN;
251 "%token-table" return PERCENT_TOKEN_TABLE;
252 "%type" return PERCENT_TYPE;
253 "%union" return PERCENT_UNION;
254 "%verbose" return PERCENT_VERBOSE;
255 "%yacc" return PERCENT_YACC;
258 "%default"[-_]"prec" DEPRECATED("%default-prec");
259 "%error"[-_]"verbose" DEPRECATED("%define parse.error verbose");
260 "%expect"[-_]"rr" DEPRECATED("%expect-rr");
261 "%file-prefix"{eqopt} DEPRECATED("%file-prefix");
262 "%fixed"[-_]"output"[-_]"files" DEPRECATED("%fixed-output-files");
263 "%name"[-_]"prefix"{eqopt} DEPRECATED("%name-prefix");
264 "%no"[-_]"default"[-_]"prec" DEPRECATED("%no-default-prec");
265 "%no"[-_]"lines" DEPRECATED("%no-lines");
266 "%output"{eqopt} DEPRECATED("%output");
267 "%pure"[-_]"parser" DEPRECATED("%pure-parser");
268 "%token"[-_]"table" DEPRECATED("%token-table");
270 "%"{id}|"%"{notletter}([[:graph:]])+ {
271 complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
276 ";" return SEMICOLON;
279 val->uniqstr = uniqstr_new (yytext);
281 bracketed_id_str = NULL;
282 BEGIN SC_AFTER_IDENTIFIER;
286 val->integer = scan_integer (yytext, 10, *loc);
289 0[xX][0-9abcdefABCDEF]+ {
290 val->integer = scan_integer (yytext, 16, *loc);
294 /* Identifiers may not start with a digit. Yet, don't silently
295 accept "1FOO" as "1 FOO". */
297 complain (loc, complaint, _("invalid identifier: %s"), quote (yytext));
301 "'" token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
304 "\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
307 "%{" code_start = loc->start; BEGIN SC_PROLOGUE;
309 /* Code in between braces. */
313 code_start = loc->start;
314 BEGIN SC_BRACED_CODE;
317 /* Semantic predicate. */
318 "%?"[ \f\n\t\v]*"{" {
320 code_start = loc->start;
325 "<*>" return TAG_ANY;
326 "<>" return TAG_NONE;
328 obstack_grow (&obstack_for_string, yytext + 1, yyleng - 2);
330 val->uniqstr = uniqstr_new (last_string);
336 token_start = loc->start;
341 static int percent_percent_count;
342 if (++percent_percent_count == 2)
344 return PERCENT_PERCENT;
348 bracketed_id_str = NULL;
349 bracketed_id_start = loc->start;
350 bracketed_id_context_state = YY_START;
351 BEGIN SC_BRACKETED_ID;
354 [^\[%A-Za-z0-9_<>{}\"\'*;|=/, \f\n\t\v]+|. {
355 complain (loc, complaint, "%s: %s",
356 ngettext ("invalid character", "invalid characters", yyleng),
357 quote_mem (yytext, yyleng));
361 loc->start = loc->end = scanner_cursor;
367 /*--------------------------------------------------------------.
368 | Supporting \0 complexifies our implementation for no expected |
370 `--------------------------------------------------------------*/
372 <SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_TAG>
374 \0 complain (loc, complaint, _("invalid null character"));
378 /*-----------------------------------------------------------------.
379 | Scanning after an identifier, checking whether a colon is next. |
380 `-----------------------------------------------------------------*/
382 <SC_AFTER_IDENTIFIER>
385 if (bracketed_id_str)
387 ROLLBACK_CURRENT_TOKEN;
388 BEGIN SC_RETURN_BRACKETED_ID;
394 bracketed_id_start = loc->start;
395 bracketed_id_context_state = YY_START;
396 BEGIN SC_BRACKETED_ID;
400 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
405 ROLLBACK_CURRENT_TOKEN;
406 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
411 BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
417 /*--------------------------------.
418 | Scanning bracketed identifiers. |
419 `--------------------------------*/
424 if (bracketed_id_str)
426 complain (loc, complaint,
427 _("unexpected identifier in bracketed name: %s"),
432 bracketed_id_str = uniqstr_new (yytext);
433 bracketed_id_loc = *loc;
437 BEGIN bracketed_id_context_state;
438 if (bracketed_id_str)
440 if (INITIAL == bracketed_id_context_state)
442 val->uniqstr = bracketed_id_str;
443 bracketed_id_str = 0;
444 *loc = bracketed_id_loc;
449 complain (loc, complaint, _("an identifier expected"));
452 [^\].A-Za-z0-9_/ \f\n\t\v]+|. {
453 complain (loc, complaint, "%s: %s",
454 ngettext ("invalid character in bracketed name",
455 "invalid characters in bracketed name", yyleng),
456 quote_mem (yytext, yyleng));
460 BEGIN bracketed_id_context_state;
461 unexpected_eof (bracketed_id_start, "]");
465 <SC_RETURN_BRACKETED_ID>
468 ROLLBACK_CURRENT_TOKEN;
469 val->uniqstr = bracketed_id_str;
470 bracketed_id_str = 0;
471 *loc = bracketed_id_loc;
478 /*---------------------------------------------------------------.
479 | Scanning a Yacc comment. The initial '/ *' is already eaten. |
480 `---------------------------------------------------------------*/
484 "*/" BEGIN context_state;
486 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
490 /*------------------------------------------------------------.
491 | Scanning a C comment. The initial '/ *' is already eaten. |
492 `------------------------------------------------------------*/
496 "*"{splice}"/" STRING_GROW; BEGIN context_state;
497 <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
501 /*--------------------------------------------------------------.
502 | Scanning a line comment. The initial '//' is already eaten. |
503 `--------------------------------------------------------------*/
507 "\n" STRING_GROW; BEGIN context_state;
508 {splice} STRING_GROW;
509 <<EOF>> BEGIN context_state;
513 /*------------------------------------------------.
514 | Scanning a Bison string, including its escapes. |
515 | The initial quote is already eaten. |
516 `------------------------------------------------*/
521 if (yytext[0] == '\n')
522 unexpected_newline (token_start, "\"");
524 loc->start = token_start;
525 val->chars = last_string;
530 unexpected_eof (token_start, "\"");
532 loc->start = token_start;
533 val->chars = last_string;
539 /*----------------------------------------------------------.
540 | Scanning a Bison character literal, decoding its escapes. |
541 | The initial quote is already eaten. |
542 `----------------------------------------------------------*/
544 <SC_ESCAPED_CHARACTER>
548 loc->start = token_start;
549 val->character = last_string[0];
551 /* FIXME: Eventually, make these errors. */
552 if (last_string[0] == '\0')
554 complain (loc, Wother, _("empty character literal"));
555 /* '\0' seems dangerous even if we are about to complain. */
556 val->character = '\'';
558 else if (last_string[1] != '\0')
559 complain (loc, Wother,
560 _("extra characters in character literal"));
562 if (yytext[0] == '\n')
563 unexpected_newline (token_start, "'");
570 loc->start = token_start;
571 val->character = last_string[0];
573 /* FIXME: Eventually, make these errors. */
574 if (last_string[0] == '\0')
576 complain (loc, Wother, _("empty character literal"));
577 /* '\0' seems dangerous even if we are about to complain. */
578 val->character = '\'';
580 else if (last_string[1] != '\0')
581 complain (loc, Wother,
582 _("extra characters in character literal"));
584 unexpected_eof (token_start, "'");
591 /*-----------------------------------------------------------.
592 | Scanning a Bison nested tag. The initial angle bracket is |
594 `-----------------------------------------------------------*/
603 loc->start = token_start;
604 val->uniqstr = uniqstr_new (last_string);
613 "<"+ STRING_GROW; nesting += yyleng;
616 unexpected_eof (token_start, ">");
618 loc->start = token_start;
619 val->uniqstr = uniqstr_new (last_string);
626 /*----------------------------.
627 | Decode escaped characters. |
628 `----------------------------*/
630 <SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
633 unsigned long int c = strtoul (yytext + 1, NULL, 8);
634 if (!c || UCHAR_MAX < c)
635 complain (loc, complaint, _("invalid number after \\-escape: %s"),
638 obstack_1grow (&obstack_for_string, c);
641 \\x[0-9abcdefABCDEF]+ {
642 verify (UCHAR_MAX < ULONG_MAX);
643 unsigned long int c = strtoul (yytext + 2, NULL, 16);
644 if (!c || UCHAR_MAX < c)
645 complain (loc, complaint, _("invalid number after \\-escape: %s"),
648 obstack_1grow (&obstack_for_string, c);
651 \\a obstack_1grow (&obstack_for_string, '\a');
652 \\b obstack_1grow (&obstack_for_string, '\b');
653 \\f obstack_1grow (&obstack_for_string, '\f');
654 \\n obstack_1grow (&obstack_for_string, '\n');
655 \\r obstack_1grow (&obstack_for_string, '\r');
656 \\t obstack_1grow (&obstack_for_string, '\t');
657 \\v obstack_1grow (&obstack_for_string, '\v');
659 /* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
660 \\("\""|"'"|"?"|"\\") obstack_1grow (&obstack_for_string, yytext[1]);
662 \\(u|U[0-9abcdefABCDEF]{4})[0-9abcdefABCDEF]{4} {
663 int c = convert_ucn_to_byte (yytext);
665 complain (loc, complaint, _("invalid number after \\-escape: %s"),
668 obstack_1grow (&obstack_for_string, c);
671 char const *p = yytext + 1;
672 /* Quote only if escaping won't make the character visible. */
673 if (c_isspace ((unsigned char) *p) && c_isprint ((unsigned char) *p))
676 p = quotearg_style_mem (escape_quoting_style, p, 1);
677 complain (loc, complaint, _("invalid character after \\-escape: %s"),
682 /*--------------------------------------------.
683 | Scanning user-code characters and strings. |
684 `--------------------------------------------*/
686 <SC_CHARACTER,SC_STRING>
688 {splice}|\\{splice}[^\n\[\]] STRING_GROW;
693 "'" STRING_GROW; BEGIN context_state;
694 \n unexpected_newline (token_start, "'"); BEGIN context_state;
695 <<EOF>> unexpected_eof (token_start, "'"); BEGIN context_state;
700 "\"" STRING_GROW; BEGIN context_state;
701 \n unexpected_newline (token_start, "\""); BEGIN context_state;
702 <<EOF>> unexpected_eof (token_start, "\""); BEGIN context_state;
706 /*---------------------------------------------------.
707 | Strings, comments etc. can be found in user code. |
708 `---------------------------------------------------*/
710 <SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE,SC_PREDICATE>
714 context_state = YY_START;
715 token_start = loc->start;
720 context_state = YY_START;
721 token_start = loc->start;
726 context_state = YY_START;
727 token_start = loc->start;
732 context_state = YY_START;
733 BEGIN SC_LINE_COMMENT;
739 /*-----------------------------------------------------------.
740 | Scanning some code in braces (actions, predicates). The |
741 | initial "{" is already eaten. |
742 `-----------------------------------------------------------*/
744 <SC_BRACED_CODE,SC_PREDICATE>
746 "{"|"<"{splice}"%" STRING_GROW; nesting++;
747 "%"{splice}">" STRING_GROW; nesting--;
749 /* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly
751 "<"{splice}"<" STRING_GROW;
754 int token = (YY_START == SC_BRACED_CODE) ? BRACED_CODE : BRACED_PREDICATE;
755 unexpected_eof (code_start, "}");
757 loc->start = code_start;
758 val->code = last_string;
767 obstack_1grow (&obstack_for_string, '}');
773 loc->start = code_start;
774 val->code = last_string;
788 loc->start = code_start;
789 val->code = last_string;
791 return BRACED_PREDICATE;
794 obstack_1grow (&obstack_for_string, '}');
798 /*--------------------------------------------------------------.
799 | Scanning some prologue: from "%{" (already scanned) to "%}". |
800 `--------------------------------------------------------------*/
806 loc->start = code_start;
807 val->chars = last_string;
813 unexpected_eof (code_start, "%}");
815 loc->start = code_start;
816 val->chars = last_string;
823 /*---------------------------------------------------------------.
824 | Scanning the epilogue (everything after the second "%%", which |
825 | has already been eaten). |
826 `---------------------------------------------------------------*/
832 loc->start = code_start;
833 val->chars = last_string;
840 /*-----------------------------------------------------.
841 | By default, grow the string obstack with the input. |
842 `-----------------------------------------------------*/
844 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>. |
845 <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE>\n STRING_GROW;
849 /* Read bytes from FP into buffer BUF of size SIZE. Return the
850 number of bytes read. Remove '\r' from input, treating \r\n
851 and isolated \r as \n. */
854 no_cr_read (FILE *fp, char *buf, size_t size)
856 size_t bytes_read = fread (buf, 1, size, fp);
859 char *w = memchr (buf, '\r', bytes_read);
863 char const *lim = buf + bytes_read;
867 /* Found an '\r'. Treat it like '\n', but ignore any
868 '\n' that immediately follows. */
873 if (ch != '\n' && ungetc (ch, fp) != ch)
879 /* Copy until the next '\r'. */
885 while ((*w++ = *r++) != '\r');
897 /*------------------------------------------------------.
898 | Scan NUMBER for a base-BASE integer at location LOC. |
899 `------------------------------------------------------*/
901 static unsigned long int
902 scan_integer (char const *number, int base, location loc)
904 verify (INT_MAX < ULONG_MAX);
905 unsigned long int num = strtoul (number, NULL, base);
909 complain (&loc, complaint, _("integer out of range: %s"),
918 /*------------------------------------------------------------------.
919 | Convert universal character name UCN to a single-byte character, |
920 | and return that character. Return -1 if UCN does not correspond |
921 | to a single-byte character. |
922 `------------------------------------------------------------------*/
925 convert_ucn_to_byte (char const *ucn)
927 verify (UCHAR_MAX <= INT_MAX);
928 unsigned long int code = strtoul (ucn + 2, NULL, 16);
930 /* FIXME: Currently we assume Unicode-compatible unibyte characters
931 on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
932 non-ASCII hosts we support only the portable C character set.
933 These limitations should be removed once we add support for
934 multibyte characters. */
936 if (UCHAR_MAX < code)
939 #if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
941 /* A non-ASCII host. Use CODE to index into a table of the C
942 basic execution character set, which is guaranteed to exist on
943 all Standard C platforms. This table also includes '$', '@',
944 and '`', which are not in the basic execution character set but
945 which are unibyte characters on all the platforms that we know
947 static signed char const table[] =
949 '\0', -1, -1, -1, -1, -1, -1, '\a',
950 '\b', '\t', '\n', '\v', '\f', '\r', -1, -1,
951 -1, -1, -1, -1, -1, -1, -1, -1,
952 -1, -1, -1, -1, -1, -1, -1, -1,
953 ' ', '!', '"', '#', '$', '%', '&', '\'',
954 '(', ')', '*', '+', ',', '-', '.', '/',
955 '0', '1', '2', '3', '4', '5', '6', '7',
956 '8', '9', ':', ';', '<', '=', '>', '?',
957 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
958 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
959 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
960 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
961 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
962 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
963 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
964 'x', 'y', 'z', '{', '|', '}', '~'
967 code = code < sizeof table ? table[code] : -1;
975 /*---------------------------------------------------------------------.
976 | Handle '#line INT( "FILE")?\n'. ARGS has already skipped '#line '. |
977 `---------------------------------------------------------------------*/
980 handle_syncline (char *args, location loc)
983 unsigned long int lineno = strtoul (args, &file, 10);
984 if (INT_MAX <= lineno)
986 complain (&loc, Wother, _("line number overflow"));
990 file = strchr (file, '"');
993 *strchr (file + 1, '"') = '\0';
994 current_file = uniqstr_new (file + 1);
996 boundary_set (&scanner_cursor, current_file, lineno, 1);
1000 /*----------------------------------------------------------------.
1001 | For a token or comment starting at START, report message MSGID, |
1002 | which should say that an end marker was found before |
1003 | the expected TOKEN_END. |
1004 `----------------------------------------------------------------*/
1007 unexpected_end (boundary start, char const *msgid, char const *token_end)
1011 loc.end = scanner_cursor;
1012 token_end = quote (token_end);
1013 /* Instead of '\'', display "'". */
1014 if (STREQ (token_end, "'\\''"))
1015 token_end = "\"'\"";
1016 complain (&loc, complaint, _(msgid), token_end);
1020 /*------------------------------------------------------------------------.
1021 | Report an unexpected EOF in a token or comment starting at START. |
1022 | An end of file was encountered and the expected TOKEN_END was missing. |
1023 `------------------------------------------------------------------------*/
1026 unexpected_eof (boundary start, char const *token_end)
1028 unexpected_end (start, N_("missing %s at end of file"), token_end);
1032 /*----------------------------------------.
1033 | Likewise, but for unexpected newlines. |
1034 `----------------------------------------*/
1037 unexpected_newline (boundary start, char const *token_end)
1039 unexpected_end (start, N_("missing %s at end of line"), token_end);
1043 /*-------------------------.
1044 | Initialize the scanner. |
1045 `-------------------------*/
1048 gram_scanner_initialize (void)
1050 obstack_init (&obstack_for_string);
1054 /*-----------------------------------------------.
1055 | Free all the memory allocated to the scanner. |
1056 `-----------------------------------------------*/
1059 gram_scanner_free (void)
1061 obstack_free (&obstack_for_string, 0);
1062 /* Reclaim Flex's buffers. */