using namespace std;
-ILexer::ILexer() : line(-1), column(-1)
+ILexer::ILexer(istream& in) : line(-1), column(-1), in_stream(in)
{
}
{
}
-void ILexer::setInput(char* in)
-{
- line = 1;
- column = 0;
- input = new istringstream( string( in ) );
- consume();
-}
-
-void ILexer::setInput(string& in)
-{
- line = 1;
- column = 0;
- input = new istringstream( in );
- consume();
-}
-
-void ILexer::setInput(istream* in)
-{
- line = 1;
- column = 0;
- input = in;
- consume();
-}
-
bool ILexer::eof(void)
{
- return ((input == NULL) || (input->eof()));
+ return in_stream.eof();
}
void ILexer::consume(void)
{
- if(input->eof())
+ if(in_stream.eof())
{
current = EOF;
}
else
{
- current = input->get();
+ current = in_stream.get();
if(current == '\n')
{
line++;
int line;
int column;
char current;
- std::istream* input;
+ std::istream& in_stream;
public:
- ILexer();
+ ILexer(std::istream& in);
virtual ~ILexer();
-
- void setInput(char* in);
- void setInput(std::string& in);
- void setInput(std::istream* in);
-
void consume(void);
void match(char x);
bool eof(void);
-
virtual Token next(void) = 0;
};