1 //////////////////////////////////////////////////////////////////////////////
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are welcomed to incorporate any part of ADLib and Prop into
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
18 // This software is still under development and we welcome(read crave for)
19 // any suggestions and help from the users.
21 // Allen Leung (leunga@cs.nyu.edu)
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef iostream_lexer_buffer_h
26 #define iostream_lexer_buffer_h
28 #include <AD/automata/lexerbuf.h> // lexer buffer
31 //////////////////////////////////////////////////////////////////////////////
32 // IOstream based lexer buffers.
33 //////////////////////////////////////////////////////////////////////////////
34 class IOLexerBuffer
: public LexerBuffer
{
36 ///////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////
39 typedef LexerBuffer Super
;
40 typedef Super::Symbol Symbol
;
41 typedef Super::State State
;
42 typedef Super::Offset Offset
;
43 typedef Super::Rule Rule
;
46 ///////////////////////////////////////////////////////////////////////////
47 // Internal buffer and other members
48 ///////////////////////////////////////////////////////////////////////////
49 size_t buffer_size
; // size of the buffer
50 std::istream
* input
; // input stream
53 ///////////////////////////////////////////////////////////////////////////
54 // Constructor and destructor
55 ///////////////////////////////////////////////////////////////////////////
57 IOLexerBuffer(std::istream
&);
58 virtual ~IOLexerBuffer();
60 ///////////////////////////////////////////////////////////////////////////
62 ///////////////////////////////////////////////////////////////////////////
63 virtual void set_stream (std::istream
&);
66 ///////////////////////////////////////////////////////////////////////////
67 // Default method for filling the buffer.
68 // This should be redefined in derive classes
69 ///////////////////////////////////////////////////////////////////////////
70 virtual size_t fill_buffer();
71 virtual size_t read_buffer(char *, size_t);
72 void allocate_buffer(size_t);