Vcsn  2.8
Be Rational
flex-lexer.hh
Go to the documentation of this file.
1 // -*-C++-*-
2 // FlexLexer.h -- define interfaces for lexical analyzer classes generated
3 // by flex
4 
5 // Copyright (c) 1993 The Regents of the University of California.
6 // All rights reserved.
7 //
8 // This code is derived from software contributed to Berkeley by
9 // Kent Williams and Tom Epperly.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions
13 // are met:
14 
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 
21 // Neither the name of the University nor the names of its contributors
22 // may be used to endorse or promote products derived from this software
23 // without specific prior written permission.
24 
25 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
26 // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
27 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE.
29 
30 // This file defines FlexLexer, an abstract class which specifies the
31 // external interface provided to flex C++ lexer objects, and yyFlexLexer,
32 // which defines a particular lexer class.
33 //
34 // If you want to create multiple lexer classes, you use the -P flag
35 // to rename each yyFlexLexer to some other xxFlexLexer. You then
36 // include <FlexLexer.h> in your other sources once per lexer class:
37 //
38 // #undef yyFlexLexer
39 // #define yyFlexLexer xxFlexLexer
40 // #include <FlexLexer.h>
41 //
42 // #undef yyFlexLexer
43 // #define yyFlexLexer zzFlexLexer
44 // #include <FlexLexer.h>
45 // ...
46 
47 #ifndef VCSN_MISC_FLEX_LEXER_HH
48 # define VCSN_MISC_FLEX_LEXER_HH
49 
50 # include <iosfwd>
51 # include <ostream>
52 
53 # ifndef FLEX_STD
54 # define FLEX_STD std::
55 # endif
56 
58 typedef int yy_state_type;
59 
60 class FlexLexer
61 {
62 public:
63  virtual ~FlexLexer() { }
64 
65  const char* YYText() const { return yytext; }
66  int YYLeng() const { return yyleng; }
67 
68  virtual void yy_switch_to_buffer( yy_buffer_state* new_buffer ) = 0;
69  virtual yy_buffer_state* yy_create_buffer( std::istream* s, int size ) = 0;
70  virtual void yy_delete_buffer( yy_buffer_state* b ) = 0;
71  virtual void yyrestart( std::istream* s ) = 0;
72 
73 #if 2 <= YY_FLEX_MAJOR_VERSION && 6 <= YY_FLEX_MINOR_VERSION
74  virtual yy_buffer_state* yy_create_buffer( std::istream& s, int size ) = 0;
75  virtual void switch_streams(std::istream& new_in, std::ostream& new_out ) = 0;
76  virtual void yyrestart( std::istream& s ) = 0;
77 #endif
78 
79  // Switch to new input/output streams. A nil stream pointer
80  // indicates "keep the current one".
81  virtual void switch_streams( std::istream* new_in = nullptr,
82  std::ostream* new_out = nullptr ) = 0;
83  int lineno() const { return yylineno; }
84 
85  int debug() const { return yy_flex_debug; }
86  void set_debug( int flag ) { yy_flex_debug = flag; }
87 
88 protected:
89  char* yytext;
90  int yyleng;
91  int yylineno; // only maintained if you use %option yylineno
92  int yy_flex_debug; // only has effect with -d or "%option debug"
93 };
94 
96 
97 void *yyalloc (size_t);
98 void *yyrealloc (void *, size_t);
99 void yyfree (void *);
100 
101 class yyFlexLexer : public FlexLexer
102 {
103 public:
104  // arg_yyin and arg_yyout default to the cin and cout, but we
105  // only make that assignment when initializing in yylex().
106  yyFlexLexer( std::istream& arg_yyin, std::ostream& arg_yyout );
107  yyFlexLexer( std::istream* arg_yyin = nullptr, std::ostream* arg_yyout = nullptr );
108 
109 private:
110  void ctor_common();
111 
112 public:
113 
114  virtual ~yyFlexLexer();
115 
116  void yy_switch_to_buffer( yy_buffer_state* new_buffer );
117  yy_buffer_state* yy_create_buffer( std::istream* s, int size );
119  void yyrestart( std::istream* s );
120 
121  void yypush_buffer_state( yy_buffer_state* new_buffer );
122  void yypop_buffer_state();
123 
124  // The signature of yylex.
125  YY_DECL_();
126 
127  void scan_open_(std::istream& f);
128 
129  void scan_close_();
130 
132 
133  virtual void switch_streams(std::istream* new_in,
134  std::ostream* new_out = nullptr );
135  virtual int yywrap();
136 
137 #if 2 <= YY_FLEX_MAJOR_VERSION && 6 <= YY_FLEX_MINOR_VERSION
138  virtual yy_buffer_state* yy_create_buffer( std::istream& s, int size );
139  void yy_init_buffer( yy_buffer_state* b, std::istream& s );
140  virtual void switch_streams(std::istream& new_in, std::ostream& new_out );
141  virtual void yyrestart( std::istream& s );
142 
143  std::istream yyin; // input source for default LexerInput
144  std::istream& yyinput_stream() { return yyin; }
145 #else
146  std::istream * yyin; // input source for default LexerInput
147  std::istream& yyinput_stream() { return *yyin; }
148 #endif
149  void putback(char c) { yyinput_stream().putback(c); }
150 
151 protected:
152  virtual int LexerInput( char* buf, int max_size );
153  virtual void LexerOutput( const char* buf, int size );
154  virtual void LexerError( const char* msg );
155 
156  void yyunput( int c, char* buf_ptr );
157  int yyinput();
158 
159  void yy_load_buffer_state();
160  void yy_init_buffer( yy_buffer_state* b, std::istream* s );
161  void yy_flush_buffer( yy_buffer_state* b );
162 
166 
167  void yy_push_state( int new_state );
168  void yy_pop_state();
169  int yy_top_state();
170 
171  yy_state_type yy_get_previous_state();
172  yy_state_type yy_try_NUL_trans( yy_state_type current_state );
173  int yy_get_next_buffer();
174 
175 #if 2 <= YY_FLEX_MAJOR_VERSION && 6 <= YY_FLEX_MINOR_VERSION
176  std::ostream yyout; // output sink for default LexerOutput
177 #else
178  std::ostream * yyout; // output sink for default LexerOutput
179 #endif
180 
181  // yy_hold_char holds the character lost when yytext is formed.
183 
184  // Number of characters read into yy_ch_buf.
186 
187  // Points to current character in buffer.
188  char* yy_c_buf_p;
189 
190  int yy_init; // whether we need to initialize
191  int yy_start; // start state number
192 
193  // Flag which is used to allow yywrap()'s to do buffer switches
194  // instead of setting up a fresh yyin. A bit of a hack ...
196 
197 
201  void yyensure_buffer_stack(void);
202 
203  // The following are not always needed, but may be depending
204  // on use of certain flex features (like REJECT or yymore()).
205 
208 
211 
215 
216  int yy_lp;
218 
223 };
224 
226 
227 #endif // !VCSN_MISC_FLEX_LEXER_HH
void putback(char c)
Definition: flex-lexer.hh:149
char * yy_last_accepting_cpos
Definition: flex-lexer.hh:207
int yy_prev_more_offset
Definition: flex-lexer.hh:222
int yy_state_type
Definition: flex-lexer.hh:57
virtual yy_buffer_state * yy_create_buffer(std::istream *s, int size)=0
int * yy_full_state
Definition: flex-lexer.hh:213
void set_debug(int flag)
Definition: flex-lexer.hh:86
yy_buffer_state ** yy_buffer_stack
Stack as an array.
Definition: flex-lexer.hh:200
int yylineno
Definition: flex-lexer.hh:91
virtual ~FlexLexer()
Definition: flex-lexer.hh:63
virtual void yy_delete_buffer(yy_buffer_state *b)=0
const char * YYText() const
Definition: flex-lexer.hh:65
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
int yy_more_offset
Definition: flex-lexer.hh:221
yy_state_type * yy_state_buf
Definition: flex-lexer.hh:209
#define yyFlexLexer
Definition: scan.cc:51
char * yytext
Definition: flex-lexer.hh:89
char * yy_full_match
Definition: flex-lexer.hh:212
char yy_hold_char
Definition: flex-lexer.hh:182
int * yy_start_stack
Definition: flex-lexer.hh:165
YY_FLEX_NAMESPACE_BEGIN void * yyalloc(size_t)
Definition: scan.cc:2178
vcsn::rat::location location
Pairs of positions in a file/stream.
Definition: fwd.hh:36
#define YY_DECL_(Class)
Definition: parse.hh:1197
std::istream * yyin
Definition: flex-lexer.hh:146
int lineno() const
Definition: flex-lexer.hh:83
size_t yy_buffer_stack_top
index of top of stack.
Definition: flex-lexer.hh:198
int yyleng
Definition: flex-lexer.hh:90
int YYLeng() const
Definition: flex-lexer.hh:66
yy_state_type * yy_state_ptr
Definition: flex-lexer.hh:210
virtual void switch_streams(std::istream *new_in=nullptr, std::ostream *new_out=nullptr)=0
int debug() const
Definition: flex-lexer.hh:85
size_t yy_buffer_stack_max
capacity of stack.
Definition: flex-lexer.hh:199
location loc
Definition: flex-lexer.hh:131
virtual void yyrestart(std::istream *s)=0
void * yyrealloc(void *, size_t)
Definition: scan.cc:2183
void yyfree(void *)
Definition: scan.cc:2196
virtual void yy_switch_to_buffer(yy_buffer_state *new_buffer)=0
std::ostream * yyout
Definition: flex-lexer.hh:178
int yy_start_stack_ptr
Definition: flex-lexer.hh:163
int yy_did_buffer_switch_on_eof
Definition: flex-lexer.hh:195
int yy_flex_debug
Definition: flex-lexer.hh:92
int yy_more_flag
Definition: flex-lexer.hh:219
char * yy_c_buf_p
Definition: flex-lexer.hh:188
#define YY_FLEX_NAMESPACE_END
Definition: scan.hh:9
int yy_start_stack_depth
Definition: flex-lexer.hh:164
weightset_mixin< detail::b_impl > b
Definition: fwd.hh:48
yy_state_type yy_last_accepting_state
Definition: flex-lexer.hh:206
std::istream & yyinput_stream()
Definition: flex-lexer.hh:147
int yy_looking_for_trail_begin
Definition: flex-lexer.hh:217