aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-01-10 21:04:17 +0000
committerMike Buland <eichlan@xagasoft.com>2011-01-10 21:04:17 +0000
commit2ba3f84ab559da02a11aa000b3cecb3b3668af61 (patch)
tree266f450b512f607ec54d54af4fa8c13fdbe7ef91 /src/parser.cpp
parentea18007633b31901f2ae275cc0576c3f7ce99fc9 (diff)
parent3611f253f6fdfa4954d374ab85ddaa7f799c130c (diff)
downloadlibbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.tar.gz
libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.tar.bz2
libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.tar.xz
libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.zip
Merged in the core branch. This is a major update that fixes many things, and
changes many others, including source files that were deleted and renamed. Before doing this update, I reccomend a full clean, or even a fresh checkout. Things to note, most outstanding about this update: - Bu::Socket was changed to Bu::TcpSocket and the default mode is blocking. - All templatized container classes are SharedCore now, which is good, but SharedCore is inherently non-reentrant safe. However, all SharedCore classes have a "clone" function that return a non-shared copy of the object, safe for passing into a reentrant safe function accessing shared memory.
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index e4e8ae5..4ad4ff9 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -22,16 +22,25 @@ void Bu::Parser::popLexer()
22 delete sLexer.peekPop(); 22 delete sLexer.peekPop();
23} 23}
24 24
25Lexer::Token *Bu::Parser::popToken()
26{
27 return sToken.peekPop();
28}
29
30void Bu::Parser::pushToken( Lexer::Token *pTok )
31{
32 sToken.push( pTok );
33}
34
25void Bu::Parser::parse() 35void Bu::Parser::parse()
26{ 36{
27 int iCurNt = iRootNonTerminal; 37 int iCurNt = iRootNonTerminal;
28 Lexer::Token *ptCur = sLexer.peek()->nextToken(); 38 Lexer::Token *ptCur = sLexer.peek()->nextToken();
29 sio << "Token: " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; 39 sio << "Token(a): " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl;
30 selectProduction( iCurNt, ptCur ); 40 selectProduction( iCurNt, ptCur );
31 41
32 while( !sState.isEmpty() ) 42 while( !sState.isEmpty() )
33 { 43 {
34 sio << "Currently: " << *sState.peek() << sio.nl;
35 switch( (*sState.peek()).eType ) 44 switch( (*sState.peek()).eType )
36 { 45 {
37 case State::typeTerminal: 46 case State::typeTerminal:
@@ -42,7 +51,7 @@ void Bu::Parser::parse()
42 advanceState(); 51 advanceState();
43 delete ptCur; 52 delete ptCur;
44 ptCur = sLexer.peek()->nextToken(); 53 ptCur = sLexer.peek()->nextToken();
45 sio << "Token: " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; 54 sio << "Token(b): " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl;
46 } 55 }
47 else 56 else
48 { 57 {
@@ -59,7 +68,7 @@ void Bu::Parser::parse()
59 sToken.push( ptCur ); 68 sToken.push( ptCur );
60 69
61 ptCur = sLexer.peek()->nextToken(); 70 ptCur = sLexer.peek()->nextToken();
62 sio << "Token: " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; 71 sio << "Token(c): " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl;
63 } 72 }
64 else 73 else
65 { 74 {
@@ -72,7 +81,7 @@ void Bu::Parser::parse()
72 << (*sState.peek()).iIndex << sio.nl; 81 << (*sState.peek()).iIndex << sio.nl;
73 { 82 {
74 int iNt = (*sState.peek()).iIndex; 83 int iNt = (*sState.peek()).iIndex;
75 advanceState(); 84 sio << "Current state: " << *sState.peek() << sio.nl;
76 if( !selectProduction( iNt, ptCur ) ) 85 if( !selectProduction( iNt, ptCur ) )
77 { 86 {
78 throw Bu::ExceptionBase("Error parsing code."); 87 throw Bu::ExceptionBase("Error parsing code.");
@@ -132,7 +141,11 @@ bool Bu::Parser::selectProduction( int iNt, Lexer::Token *ptCur )
132 } 141 }
133 } 142 }
134 if( nt.bCanSkip ) 143 if( nt.bCanSkip )
144 {
145 sio << "Nothing matches, skipping non-terminal." << sio.nl;
146 advanceState();
135 return true; 147 return true;
148 }
136 sio << "-->(Found nothing)" << sio.nl; 149 sio << "-->(Found nothing)" << sio.nl;
137 return false; 150 return false;
138} 151}
@@ -148,6 +161,7 @@ void Bu::Parser::advanceState()
148 sio.decIndent(); 161 sio.decIndent();
149 sState.pop(); 162 sState.pop();
150 sio << "State advanced, End of production." << sio.nl; 163 sio << "State advanced, End of production." << sio.nl;
164 advanceState();
151 return; 165 return;
152 } 166 }
153 sio << "State advanced, now: " << *(sState.peek()) << sio.nl; 167 sio << "State advanced, now: " << *(sState.peek()) << sio.nl;
@@ -191,6 +205,11 @@ int Bu::Parser::getNonTerminalId( const Bu::FString &sName )
191 return hNonTerminalName.get( sName ); 205 return hNonTerminalName.get( sName );
192} 206}
193 207
208bool Bu::Parser::hasNonTerminal( const Bu::FString &sName )
209{
210 return hNonTerminalName.has( sName );
211}
212
194int Bu::Parser::addReduction( const Bu::FString &sName, const Reduction &r ) 213int Bu::Parser::addReduction( const Bu::FString &sName, const Reduction &r )
195{ 214{
196 int iId = aReduction.getSize(); 215 int iId = aReduction.getSize();
@@ -217,6 +236,11 @@ int Bu::Parser::getReductionId( const Bu::FString &sName )
217 return hReductionName.get( sName ); 236 return hReductionName.get( sName );
218} 237}
219 238
239bool Bu::Parser::hasReduction( const Bu::FString &sName )
240{
241 return hReductionName.has( sName );
242}
243
220// 244//
221// Bu::Parser::State 245// Bu::Parser::State
222// 246//