diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-10-12 06:09:48 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-10-12 06:09:48 +0000 |
commit | 1ee5f374ed986333d5cdbbf41390f1c4c755a8e3 (patch) | |
tree | 67b02598d3dca87a82263629a1290bd7b7a79006 /src/parser.cpp | |
parent | 313e28df2a8776c82f5493aef6fe44ad40f1935a (diff) | |
download | libbu++-1ee5f374ed986333d5cdbbf41390f1c4c755a8e3.tar.gz libbu++-1ee5f374ed986333d5cdbbf41390f1c4c755a8e3.tar.bz2 libbu++-1ee5f374ed986333d5cdbbf41390f1c4c755a8e3.tar.xz libbu++-1ee5f374ed986333d5cdbbf41390f1c4c755a8e3.zip |
This commit has a minor tweak to the variant class to make it easier to use,
and introduces the parser and lexer classes. I also made a test for parser and
put it in the tools directory. That is silly, it shouldn't be. However, it's
necesarry right now, because I don't want to do a full build to compile all
the parser tests.
However, this commit doesn't actually build yet. It will soon, I just wanted
to get it all committed.
Diffstat (limited to 'src/parser.cpp')
-rw-r--r-- | src/parser.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp new file mode 100644 index 0000000..7015070 --- /dev/null +++ b/src/parser.cpp | |||
@@ -0,0 +1,43 @@ | |||
1 | #include "bu/parser.h" | ||
2 | #include "bu/lexer.h" | ||
3 | |||
4 | #include "bu/sio.h" | ||
5 | using namespace Bu; | ||
6 | |||
7 | Bu::Parser::Parser() | ||
8 | { | ||
9 | } | ||
10 | |||
11 | Bu::Parser::~Parser() | ||
12 | { | ||
13 | } | ||
14 | |||
15 | void Bu::Parser::pushLexer( Lexer *pLex ) | ||
16 | { | ||
17 | sLexer.push( pLex ); | ||
18 | } | ||
19 | |||
20 | void Bu::Parser::popLexer() | ||
21 | { | ||
22 | delete sLexer.peekPop(); | ||
23 | } | ||
24 | |||
25 | void Bu::Parser::parse() | ||
26 | { | ||
27 | for(;;) | ||
28 | { | ||
29 | Bu::Lexer::Token *pToken = sLexer.peek()->nextToken(); | ||
30 | sio << sLexer.peek()->tokenToString( *pToken ) << sio.nl; | ||
31 | if( pToken->iToken < 0 ) | ||
32 | { | ||
33 | delete sLexer.peekPop(); | ||
34 | if( sLexer.isEmpty() ) | ||
35 | { | ||
36 | delete pToken; | ||
37 | return; | ||
38 | } | ||
39 | } | ||
40 | delete pToken; | ||
41 | } | ||
42 | } | ||
43 | |||