diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-10-14 00:08:50 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-10-14 00:08:50 +0000 |
commit | 8d0b7a6cd835b1a8d8dae020b8ad50ab5451b1da (patch) | |
tree | de1c1d34e0c99b92317693de53a88772e1210f94 /src/parser.cpp | |
parent | fc16fc104a038146c8ab6c2e9fad38e18663a09f (diff) | |
download | libbu++-8d0b7a6cd835b1a8d8dae020b8ad50ab5451b1da.tar.gz libbu++-8d0b7a6cd835b1a8d8dae020b8ad50ab5451b1da.tar.bz2 libbu++-8d0b7a6cd835b1a8d8dae020b8ad50ab5451b1da.tar.xz libbu++-8d0b7a6cd835b1a8d8dae020b8ad50ab5451b1da.zip |
Minor tweaks to myriad.
Diffstat (limited to 'src/parser.cpp')
-rw-r--r-- | src/parser.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index b563691..e4e8ae5 100644 --- a/src/parser.cpp +++ b/src/parser.cpp | |||
@@ -26,9 +26,8 @@ void Bu::Parser::parse() | |||
26 | { | 26 | { |
27 | int iCurNt = iRootNonTerminal; | 27 | int iCurNt = iRootNonTerminal; |
28 | Lexer::Token *ptCur = sLexer.peek()->nextToken(); | 28 | Lexer::Token *ptCur = sLexer.peek()->nextToken(); |
29 | //Lexer::Token *ptNext = sLexer.peek()->nextToken(); | 29 | sio << "Token: " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; |
30 | selectProduction( iCurNt, ptCur ); | 30 | selectProduction( iCurNt, ptCur ); |
31 | sio << "Token: " << *ptCur << sio.nl; | ||
32 | 31 | ||
33 | while( !sState.isEmpty() ) | 32 | while( !sState.isEmpty() ) |
34 | { | 33 | { |
@@ -43,7 +42,7 @@ void Bu::Parser::parse() | |||
43 | advanceState(); | 42 | advanceState(); |
44 | delete ptCur; | 43 | delete ptCur; |
45 | ptCur = sLexer.peek()->nextToken(); | 44 | ptCur = sLexer.peek()->nextToken(); |
46 | sio << "Token: " << *ptCur << sio.nl; | 45 | sio << "Token: " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; |
47 | } | 46 | } |
48 | else | 47 | else |
49 | { | 48 | { |
@@ -60,7 +59,7 @@ void Bu::Parser::parse() | |||
60 | sToken.push( ptCur ); | 59 | sToken.push( ptCur ); |
61 | 60 | ||
62 | ptCur = sLexer.peek()->nextToken(); | 61 | ptCur = sLexer.peek()->nextToken(); |
63 | sio << "Token: " << *ptCur << sio.nl; | 62 | sio << "Token: " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; |
64 | } | 63 | } |
65 | else | 64 | else |
66 | { | 65 | { |
@@ -99,12 +98,15 @@ bool Bu::Parser::selectProduction( int iNt, Lexer::Token *ptCur ) | |||
99 | { | 98 | { |
100 | if( (*i).isEmpty() ) | 99 | if( (*i).isEmpty() ) |
101 | continue; | 100 | continue; |
101 | sio << "-->(Attempting production " << iNt << ":" << j << ": " | ||
102 | << (*i).first() << ")" << sio.nl; | ||
102 | if( (*i).first().eType == State::typeTerminal || | 103 | if( (*i).first().eType == State::typeTerminal || |
103 | (*i).first().eType == State::typeTerminalPush ) | 104 | (*i).first().eType == State::typeTerminalPush ) |
104 | { | 105 | { |
105 | if( (*i).first().iIndex == ptCur->iToken ) | 106 | if( (*i).first().iIndex == ptCur->iToken ) |
106 | { | 107 | { |
107 | sState.push( (*i).begin() ); | 108 | sState.push( (*i).begin() ); |
109 | sio.incIndent(); | ||
108 | sio << "Pushing production " << j << " from nt " << iNt | 110 | sio << "Pushing production " << j << " from nt " << iNt |
109 | << sio.nl; | 111 | << sio.nl; |
110 | return true; | 112 | return true; |
@@ -113,10 +115,12 @@ bool Bu::Parser::selectProduction( int iNt, Lexer::Token *ptCur ) | |||
113 | else if( (*i).first().eType == State::typeNonTerminal ) | 115 | else if( (*i).first().eType == State::typeNonTerminal ) |
114 | { | 116 | { |
115 | sState.push( (*i).begin() ); | 117 | sState.push( (*i).begin() ); |
118 | sio.incIndent(); | ||
116 | sio << "Pushing production " << j << " from nt " << iNt | 119 | sio << "Pushing production " << j << " from nt " << iNt |
117 | << " as test." << sio.nl; | 120 | << " as test." << sio.nl; |
118 | if( !selectProduction( (*i).first().iIndex, ptCur ) ) | 121 | if( !selectProduction( (*i).first().iIndex, ptCur ) ) |
119 | { | 122 | { |
123 | sio.decIndent(); | ||
120 | sState.pop(); | 124 | sState.pop(); |
121 | sio << "Production " << j << " from nt " << iNt | 125 | sio << "Production " << j << " from nt " << iNt |
122 | << " didn't work out." << sio.nl; | 126 | << " didn't work out." << sio.nl; |
@@ -129,6 +133,7 @@ bool Bu::Parser::selectProduction( int iNt, Lexer::Token *ptCur ) | |||
129 | } | 133 | } |
130 | if( nt.bCanSkip ) | 134 | if( nt.bCanSkip ) |
131 | return true; | 135 | return true; |
136 | sio << "-->(Found nothing)" << sio.nl; | ||
132 | return false; | 137 | return false; |
133 | } | 138 | } |
134 | 139 | ||
@@ -140,6 +145,7 @@ void Bu::Parser::advanceState() | |||
140 | sState.peek()++; | 145 | sState.peek()++; |
141 | if( !sState.peek() ) | 146 | if( !sState.peek() ) |
142 | { | 147 | { |
148 | sio.decIndent(); | ||
143 | sState.pop(); | 149 | sState.pop(); |
144 | sio << "State advanced, End of production." << sio.nl; | 150 | sio << "State advanced, End of production." << sio.nl; |
145 | return; | 151 | return; |