From: Mike D. Lowis Date: Fri, 9 Mar 2012 23:44:55 +0000 (-0500) Subject: Updated lexer interface X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=2fc4293edf8a695e0de35ac875753db7b7308b2d;p=archive%2Fparse-utils.git Updated lexer interface --- diff --git a/source/lexer/ilexer.cpp b/source/lexer/ilexer.cpp index 25e260f..b90320d 100644 --- a/source/lexer/ilexer.cpp +++ b/source/lexer/ilexer.cpp @@ -4,7 +4,7 @@ using namespace std; -ILexer::ILexer() : line(-1), column(-1) +ILexer::ILexer(istream& in) : line(-1), column(-1), in_stream(in) { } @@ -12,44 +12,20 @@ ILexer::~ILexer() { } -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++; diff --git a/source/lexer/ilexer.h b/source/lexer/ilexer.h index d21768d..7ad8198 100644 --- a/source/lexer/ilexer.h +++ b/source/lexer/ilexer.h @@ -12,20 +12,14 @@ class ILexer 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; };