summaryrefslogtreecommitdiff
path: root/src/lexer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lexer.cpp')
-rw-r--r--src/lexer.cpp42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/lexer.cpp b/src/lexer.cpp
index b0d0fd1..fbcaafb 100644
--- a/src/lexer.cpp
+++ b/src/lexer.cpp
@@ -11,27 +11,55 @@ Lexer::Lexer( Bu::Stream &rIn ) :
11 iRadix( 10 ), 11 iRadix( 10 ),
12 numRangeTop('9'), 12 numRangeTop('9'),
13 ascRangeTop('a'-1), 13 ascRangeTop('a'-1),
14 eMode( modeNormal ) 14 eMode( modeNormal ),
15 iLookAheadSize( 2 ),
16 iLookAheadUsed( 0 ),
17 iLookAheadStart( 0 ),
18 aLookAhead( 0 )
15{ 19{
20 aLookAhead = new Token[iLookAheadSize];
16} 21}
17 22
18Lexer::~Lexer() 23Lexer::~Lexer()
19{ 24{
20} 25}
21 26
22Token Lexer::nextToken() 27void Lexer::nextToken()
28{
29 if( iLookAheadSize <= 1 )
30 {
31 iLookAheadSize = 0;
32 iLookAheadStart = 0;
33 }
34 else
35 {
36 iLookAheadStart = (iLookAheadStart+1)%iLookAheadSize;
37 iLookAheadSize--;
38 }
39}
40
41void Lexer::fillToken()
23{ 42{
24 switch( eMode ) 43 switch( eMode )
25 { 44 {
26 case modeNormal: 45 case modeNormal:
27 return nextTokenNormal(); 46 aLookAhead[(iLookAheadUsed+iLookAheadStart)%iLookAheadSize] =
47 nextTokenNormal();
48 break;
28 49
29 case modeCommand: 50 case modeCommand:
30 return nextTokenCommand(); 51 aLookAhead[(iLookAheadUsed+iLookAheadStart)%iLookAheadSize] =
52 nextTokenCommand();
53 break;
31 54
32 default: 55 default:
33 throw Bu::ExceptionBase("Invalid mode."); 56 throw Bu::ExceptionBase("Invalid mode.");
34 } 57 }
58
59 Bu::sio << "read["
60 << ((iLookAheadUsed+iLookAheadStart)%iLookAheadSize)
61 << "]: "
62 << aLookAhead[(iLookAheadUsed+iLookAheadStart)%iLookAheadSize].eType;
35} 63}
36 64
37Token Lexer::nextTokenNormal() 65Token Lexer::nextTokenNormal()
@@ -235,5 +263,11 @@ void Lexer::setRadix( int i )
235 263
236Token &Lexer::operator[]( int iIdx ) 264Token &Lexer::operator[]( int iIdx )
237{ 265{
266 while( iIdx >= iLookAheadUsed )
267 {
268 fillToken();
269 iLookAheadUsed++;
270 }
271 return aLookAhead[(iLookAheadStart+iIdx)%iLookAheadSize];
238} 272}
239 273