aboutsummaryrefslogtreecommitdiff
path: root/src/tools/bnfcompile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/bnfcompile.cpp')
-rw-r--r--src/tools/bnfcompile.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/tools/bnfcompile.cpp b/src/tools/bnfcompile.cpp
index 16e75a5..011ec84 100644
--- a/src/tools/bnfcompile.cpp
+++ b/src/tools/bnfcompile.cpp
@@ -1,3 +1,10 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
1#include <bu/sio.h> 8#include <bu/sio.h>
2#include <bu/lexer.h> 9#include <bu/lexer.h>
3#include <bu/parser.h> 10#include <bu/parser.h>
@@ -123,7 +130,7 @@ public:
123 } 130 }
124 } 131 }
125 132
126 virtual FString tokenToString( const Token &t ) 133 virtual String tokenToString( const Token &t )
127 { 134 {
128 switch( (TokenType)t.iToken ) 135 switch( (TokenType)t.iToken )
129 { 136 {
@@ -146,7 +153,7 @@ public:
146private: 153private:
147 Stream &rSrc; 154 Stream &rSrc;
148 QueueBuf qbIn; 155 QueueBuf qbIn;
149 FString sBuf; 156 String sBuf;
150}; 157};
151 158
152class BnfParser 159class BnfParser
@@ -201,9 +208,9 @@ private:
201 next(); 208 next();
202 if( pCur->iToken == tokIdentifier ) 209 if( pCur->iToken == tokIdentifier )
203 { 210 {
204 hTokens.insert( pCur->vExtra.get<Bu::FString>(), ++iLastToken ); 211 hTokens.insert( pCur->vExtra.get<Bu::String>(), ++iLastToken );
205 sio << "Added token[" << iLastToken << "]: " 212 sio << "Added token[" << iLastToken << "]: "
206 << pCur->vExtra.get<Bu::FString>() << sio.nl; 213 << pCur->vExtra.get<Bu::String>() << sio.nl;
207 } 214 }
208 else if( pCur->iToken == tokSemiColon ) 215 else if( pCur->iToken == tokSemiColon )
209 break; 216 break;
@@ -214,7 +221,7 @@ private:
214 221
215 void nonTerminal() 222 void nonTerminal()
216 { 223 {
217 Bu::FString sNtName = pCur->vExtra.get<Bu::FString>(); 224 Bu::String sNtName = pCur->vExtra.get<Bu::String>();
218 Parser::NonTerminal nt; 225 Parser::NonTerminal nt;
219 p.addNonTerminal( sNtName ); 226 p.addNonTerminal( sNtName );
220 sio.incIndent(); 227 sio.incIndent();
@@ -258,8 +265,8 @@ private:
258 { 265 {
259 case tokIdentifier: 266 case tokIdentifier:
260 { 267 {
261 const Bu::FString &sName = 268 const Bu::String &sName =
262 pCur->vExtra.get<Bu::FString>(); 269 pCur->vExtra.get<Bu::String>();
263 if( hTokens.has( sName ) ) 270 if( hTokens.has( sName ) )
264 { 271 {
265 pr.append( 272 pr.append(
@@ -292,8 +299,8 @@ private:
292 next(); 299 next();
293 if( pCur->iToken != tokIdentifier ) 300 if( pCur->iToken != tokIdentifier )
294 tokenError("tokIdentifier"); 301 tokenError("tokIdentifier");
295 Bu::FString sName = 302 Bu::String sName =
296 pCur->vExtra.get<Bu::FString>(); 303 pCur->vExtra.get<Bu::String>();
297 next(); 304 next();
298 if( pCur->iToken != tokCloseSquare ) 305 if( pCur->iToken != tokCloseSquare )
299 tokenError("tokCloseSquare"); 306 tokenError("tokCloseSquare");
@@ -317,8 +324,8 @@ private:
317 next(); 324 next();
318 if( pCur->iToken != tokIdentifier ) 325 if( pCur->iToken != tokIdentifier )
319 tokenError("tokIdentifier"); 326 tokenError("tokIdentifier");
320 Bu::FString sName = 327 Bu::String sName =
321 pCur->vExtra.get<Bu::FString>(); 328 pCur->vExtra.get<Bu::String>();
322 next(); 329 next();
323 if( pCur->iToken != tokCloseCurly ) 330 if( pCur->iToken != tokCloseCurly )
324 tokenError("tokCloseCurly"); 331 tokenError("tokCloseCurly");
@@ -366,14 +373,14 @@ private:
366 pCur = l.nextToken(); 373 pCur = l.nextToken();
367 } 374 }
368 375
369 void tokenError( const FString &s ) 376 void tokenError( const String &s )
370 { 377 {
371 throw ExceptionBase( ("Expected " + s + " but found " 378 throw ExceptionBase( ("Expected " + s + " but found "
372 + l.tokenToString( *pCur ) + ".").getStr() ); 379 + l.tokenToString( *pCur ) + ".").getStr() );
373 } 380 }
374 381
375private: 382private:
376 typedef Bu::Hash<Bu::FString, int> TokenHash; 383 typedef Bu::Hash<Bu::String, int> TokenHash;
377 TokenHash hTokens; 384 TokenHash hTokens;
378 BnfLexer &l; 385 BnfLexer &l;
379 BnfLexer::Token *pCur; 386 BnfLexer::Token *pCur;