]> git.saurik.com Git - bison.git/blame - src/flex-scanner.h
For push mode, convert yyparse from a macro to a function, invoke yylex
[bison.git] / src / flex-scanner.h
CommitLineData
f9bfc42a 1/* Common parts between scan-code.l, scan-gram.l, and scan-skel.l.
9f936c5e
AD
2
3 Copyright (C) 2006 Free Software Foundation, Inc.
4
5 This file is part of Bison, the GNU Compiler Compiler.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21*/
22
23#ifndef FLEX_PREFIX
24# error "FLEX_PREFIX not defined"
25#endif
26
9f936c5e
AD
27/* Pacify "gcc -Wmissing-prototypes" when flex 2.5.31 is used. */
28int FLEX_PREFIX (get_lineno) (void);
29FILE *FLEX_PREFIX (get_in) (void);
30FILE *FLEX_PREFIX (get_out) (void);
31int FLEX_PREFIX (get_leng) (void);
32char *FLEX_PREFIX (get_text) (void);
33void FLEX_PREFIX (set_lineno) (int);
34void FLEX_PREFIX (set_in) (FILE *);
35void FLEX_PREFIX (set_out) (FILE *);
36int FLEX_PREFIX (get_debug) (void);
37void FLEX_PREFIX (set_debug) (int);
38int FLEX_PREFIX (lex_destroy) (void);
39
40#define last_string FLEX_PREFIX (last_string)
41
42/* It seems to be a nice "feature" of Flex that one cannot use yytext,
43 yyleng etc. when a prefix is given, since there is no longer a
44 #define, but rather the token is actually changed in the output.
9e668899
JD
45 However, this is not true for Flex 2.5.4. */
46#ifndef yyleng
47# define yyleng FLEX_PREFIX (leng)
48#endif
49#ifndef yytext
3c40d0b5 50# define yytext FLEX_PREFIX (text)
9e668899 51#endif
9f936c5e 52
580b8926
JD
53/* Non-reentrant scanners generated by Flex 2.5.9 and later (and some earlier
54 versions according to the Flex manual) leak memory if yylex_destroy is not
55 invoked. However, yylex_destroy is not defined before Flex 2.5.9, so give
56 an implementation here that at least appears to work with Flex 2.5.4. */
57#if !defined(YY_FLEX_MAJOR_VERSION) || YY_FLEX_MAJOR_VERSION < 2 \
58 || (YY_FLEX_MAJOR_VERSION == 2 \
59 && (!defined(YY_FLEX_MINOR_VERSION) || YY_FLEX_MINOR_VERSION < 5 \
60 || (YY_FLEX_MINOR_VERSION == 5 \
61 && (!defined(YY_FLEX_SUBMINOR_VERSION) \
62 || YY_FLEX_SUBMINOR_VERSION < 9))))
63# define yylex_destroy() yy_delete_buffer (YY_CURRENT_BUFFER)
64#endif
65
9f936c5e
AD
66/* OBSTACK_FOR_STRING -- Used to store all the characters that we need to
67 keep (to construct ID, STRINGS etc.). Use the following macros to
68 use it.
69
70 Use STRING_GROW to append what has just been matched, and
71 STRING_FINISH to end the string (it puts the ending 0).
72 STRING_FINISH also stores this string in LAST_STRING, which can be
73 used, and which is used by STRING_FREE to free the last string. */
74
f9bfc42a
JD
75#ifndef FLEX_NO_OBSTACK
76
9f936c5e
AD
77static struct obstack obstack_for_string;
78
79#define STRING_GROW \
80 obstack_grow (&obstack_for_string, yytext, yyleng)
81
82#define STRING_FINISH \
83 do { \
84 obstack_1grow (&obstack_for_string, '\0'); \
85 last_string = obstack_finish (&obstack_for_string); \
86 } while (0)
87
88#define STRING_FREE \
f2e690d8 89 obstack_free (&obstack_for_string, last_string)
f9bfc42a
JD
90
91#endif