Vcsn  2.1
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 struct yy_buffer_state;
51 typedef int yy_state_type;
52 
53 class FlexLexer
54 {
55 public:
56  virtual ~FlexLexer() { }
57 
58  const char* YYText() const { return yytext; }
59  int YYLeng() const { return yyleng; }
60 
61  virtual void
62  yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
63  virtual struct yy_buffer_state*
64  yy_create_buffer( std::istream* s, int size ) = 0;
65  virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
66  virtual void yyrestart( std::istream* s ) = 0;
67 
68  // Switch to new input/output streams. A nil stream pointer
69  // indicates "keep the current one".
70  virtual void switch_streams( std::istream* new_in = nullptr,
71  std::ostream* new_out = nullptr ) = 0;
72  int lineno() const { return yylineno; }
73 
74  int debug() const { return yy_flex_debug; }
75  void set_debug( int flag ) { yy_flex_debug = flag; }
76 
77 protected:
78  char* yytext;
79  int yyleng;
80  int yylineno; // only maintained if you use %option yylineno
81  int yy_flex_debug; // only has effect with -d or "%option debug"
82 };
83 
85 
86 void *yyalloc (size_t);
87 void *yyrealloc (void *, size_t);
88 void yyfree (void *);
89 
90 class yyFlexLexer : public FlexLexer
91 {
92 public:
93  // arg_yyin and arg_yyout default to the cin and cout, but we
94  // only make that assignment when initializing in yylex().
95  yyFlexLexer( std::istream* arg_yyin = nullptr, std::ostream* arg_yyout = nullptr );
96 
97  virtual ~yyFlexLexer();
98 
99  void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
100  struct yy_buffer_state* yy_create_buffer( std::istream* s, int size );
101  void yy_delete_buffer( struct yy_buffer_state* b );
102  void yyrestart( std::istream* s );
103 
104  void yypush_buffer_state( struct yy_buffer_state* new_buffer );
105  void yypop_buffer_state();
106 
107  // The signature of yylex.
108  YY_DECL_();
109 
110  void scan_open_(std::istream& f);
111 
112  void scan_close_();
113 
115 
116  virtual void switch_streams(std::istream* new_in,
117  std::ostream* new_out = nullptr );
118  virtual int yywrap();
119 
120  std::istream* yyin; // input source for default LexerInput
121 
122 protected:
123  virtual int LexerInput( char* buf, int max_size );
124  virtual void LexerOutput( const char* buf, int size );
125  virtual void LexerError( const char* msg );
126 
127  void yyunput( int c, char* buf_ptr );
128  int yyinput();
129 
130  void yy_load_buffer_state();
131  void yy_init_buffer( struct yy_buffer_state* b, std::istream* s );
132  void yy_flush_buffer( struct yy_buffer_state* b );
133 
137 
138  void yy_push_state( int new_state );
139  void yy_pop_state();
140  int yy_top_state();
141 
144  int yy_get_next_buffer();
145 
146  std::ostream* yyout; // output sink for default LexerOutput
147 
148  // yy_hold_char holds the character lost when yytext is formed.
150 
151  // Number of characters read into yy_ch_buf.
153 
154  // Points to current character in buffer.
155  char* yy_c_buf_p;
156 
157  int yy_init; // whether we need to initialize
158  int yy_start; // start state number
159 
160  // Flag which is used to allow yywrap()'s to do buffer switches
161  // instead of setting up a fresh yyin. A bit of a hack ...
163 
164 
167  struct yy_buffer_state ** yy_buffer_stack;
168  void yyensure_buffer_stack(void);
169 
170  // The following are not always needed, but may be depending
171  // on use of certain flex features (like REJECT or yymore()).
172 
175 
178 
182 
183  int yy_lp;
185 
190 };
191 
193 
194 #endif // !VCSN_MISC_FLEX_LEXER_HH
yy_state_type * yy_state_buf
Definition: flex-lexer.hh:176
char * yy_last_accepting_cpos
Definition: flex-lexer.hh:174
size_t yy_buffer_stack_top
index of top of stack.
Definition: flex-lexer.hh:165
yy_state_type yy_get_previous_state()
void yy_pop_state()
void yy_switch_to_buffer(struct yy_buffer_state *new_buffer)
virtual void switch_streams(std::istream *new_in=nullptr, std::ostream *new_out=nullptr)=0
void yy_init_buffer(struct yy_buffer_state *b, std::istream *s)
void yyensure_buffer_stack(void)
char * yy_c_buf_p
Definition: flex-lexer.hh:155
int yy_prev_more_offset
Definition: flex-lexer.hh:189
void yy_push_state(int new_state)
weightset_mixin< detail::b_impl > b
Definition: fwd.hh:48
struct yy_buffer_state * yy_create_buffer(std::istream *s, int size)
virtual ~FlexLexer()
Definition: flex-lexer.hh:56
int * yy_start_stack
Definition: flex-lexer.hh:136
#define YY_FLEX_NAMESPACE_BEGIN
Definition: scan.hh:4
int yy_flex_debug
Definition: flex-lexer.hh:81
char * yytext
Definition: flex-lexer.hh:78
void * yyrealloc(void *, size_t)
void yyunput(int c, char *buf_ptr)
char * yy_full_match
Definition: flex-lexer.hh:179
virtual void yy_switch_to_buffer(struct yy_buffer_state *new_buffer)=0
yy_state_type yy_try_NUL_trans(yy_state_type current_state)
location loc
Definition: flex-lexer.hh:114
int lineno() const
Definition: flex-lexer.hh:72
void yy_load_buffer_state()
void yypop_buffer_state()
void yyrestart(std::istream *s)
yy_state_type * yy_state_ptr
Definition: flex-lexer.hh:177
char yy_hold_char
Definition: flex-lexer.hh:149
vcsn::rat::location location
Definition: scan.hh:17
virtual void LexerError(const char *msg)
void yy_delete_buffer(struct yy_buffer_state *b)
void yy_flush_buffer(struct yy_buffer_state *b)
void yyfree(void *)
int YYLeng() const
Definition: flex-lexer.hh:59
YY_FLEX_NAMESPACE_BEGIN void * yyalloc(size_t)
virtual void yyrestart(std::istream *s)=0
void yypush_buffer_state(struct yy_buffer_state *new_buffer)
virtual int yywrap()
int * yy_full_state
Definition: flex-lexer.hh:180
virtual struct yy_buffer_state * yy_create_buffer(std::istream *s, int size)=0
virtual void LexerOutput(const char *buf, int size)
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
size_t yy_buffer_stack_max
capacity of stack.
Definition: flex-lexer.hh:166
int yy_top_state()
int yy_state_type
Definition: flex-lexer.hh:50
const char * YYText() const
Definition: flex-lexer.hh:58
virtual void yy_delete_buffer(struct yy_buffer_state *b)=0
yyFlexLexer(std::istream *arg_yyin=nullptr, std::ostream *arg_yyout=nullptr)
int yyleng
Definition: flex-lexer.hh:79
int yy_get_next_buffer()
int yy_did_buffer_switch_on_eof
Definition: flex-lexer.hh:162
int debug() const
Definition: flex-lexer.hh:74
int yy_start_stack_ptr
Definition: flex-lexer.hh:134
int yy_more_flag
Definition: flex-lexer.hh:186
int yy_more_offset
Definition: flex-lexer.hh:188
int yy_start_stack_depth
Definition: flex-lexer.hh:135
#define YY_FLEX_NAMESPACE_END
Definition: scan.hh:9
int yy_looking_for_trail_begin
Definition: flex-lexer.hh:184
std::ostream * yyout
Definition: flex-lexer.hh:146
int yylineno
Definition: flex-lexer.hh:80
std::istream * yyin
Definition: flex-lexer.hh:120
void scan_close_()
struct yy_buffer_state ** yy_buffer_stack
Stack as an array.
Definition: flex-lexer.hh:167
virtual void switch_streams(std::istream *new_in, std::ostream *new_out=nullptr)
void scan_open_(std::istream &f)
void set_debug(int flag)
Definition: flex-lexer.hh:75
virtual ~yyFlexLexer()
yy_state_type yy_last_accepting_state
Definition: flex-lexer.hh:173
virtual int LexerInput(char *buf, int max_size)