From fc14c0f16e881607e55f04516934818091331bd3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 8 May 2013 13:36:09 -0600 Subject: Command parameters are taken as strings & decimal. You no longer need to set the radix in the current radix. --- src/lexer.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'src/lexer.cpp') diff --git a/src/lexer.cpp b/src/lexer.cpp index 2521b40..97ceb1b 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -10,7 +10,8 @@ Lexer::Lexer( Bu::Stream &rIn ) : iScale( 0 ), iRadix( 10 ), numRangeTop('9'), - ascRangeTop('a'-1) + ascRangeTop('a'-1), + eMode( modeNormal ) { } @@ -19,6 +20,21 @@ Lexer::~Lexer() } Token Lexer::nextToken() +{ + switch( eMode ) + { + case modeNormal: + return nextTokenNormal(); + + case modeCommand: + return nextTokenCommand(); + + default: + throw Bu::ExceptionBase("Invalid mode."); + } +} + +Token Lexer::nextTokenNormal() { for(;;) { @@ -151,6 +167,56 @@ Token Lexer::nextToken() } } +Token Lexer::nextTokenCommand() +{ + for(;;) + { + if( iBufPos >= sBuf.getSize() ) + { + iBufPos = -1; + return Token( Token::tEndOfLine ); + } + + if( iBufPos < 0 ) + { + if( rIn.isEos() ) + return Token( Token::tEndOfInput ); + + sBuf = rIn.readLine(); + if( sBuf.getSize() == 0 ) + { + iBufPos = -1; + continue; + } + iBufPos = 0; + } + + //Bu::println("Testing char '%1' at %2").arg( sBuf[iBufPos] ).arg( iBufPos ); + switch( sBuf[iBufPos] ) + { + case ' ': + case '\t': + iBufPos++; + break; + + default: + { + Bu::String *sTmp = new Bu::String(); + for( ; iBufPos < sBuf.getSize() ; iBufPos++ ) + { + if( sBuf[iBufPos] == ' ' || + sBuf[iBufPos] == '\t' ) + break; + + sTmp->append( sBuf[iBufPos] ); + } + return Token( Token::tString, sTmp ); + } + break; + } + } +} + void Lexer::setRadix( int i ) { iRadix = i; -- cgit v1.2.3