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/lexer.h | |
| 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/lexer.h')
| -rw-r--r-- | src/lexer.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lexer.h b/src/lexer.h new file mode 100644 index 0000000..37d268f --- /dev/null +++ b/src/lexer.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #ifndef BU_LEXER_H | ||
| 2 | #define BU_LEXER_H | ||
| 3 | |||
| 4 | #include "bu/variant.h" | ||
| 5 | |||
| 6 | namespace Bu | ||
| 7 | { | ||
| 8 | class Stream; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * The base class for creating a lexical analyzer. This is designed to work | ||
| 12 | * in tandem with the Bu::Parser class, which uses this to tokenize textual | ||
| 13 | * input. It can be used by just about anything that cares about tokens | ||
| 14 | * more than raw input, though. | ||
| 15 | */ | ||
| 16 | class Lexer | ||
| 17 | { | ||
| 18 | public: | ||
| 19 | Lexer(); | ||
| 20 | virtual ~Lexer(); | ||
| 21 | |||
| 22 | class Token | ||
| 23 | { | ||
| 24 | public: | ||
| 25 | Token(); | ||
| 26 | Token( int iToken ); | ||
| 27 | |||
| 28 | template<class t> | ||
| 29 | Token( int iToken, const t &v ) : | ||
| 30 | iToken( iToken ), | ||
| 31 | vExtra( v ) | ||
| 32 | { | ||
| 33 | } | ||
| 34 | int iToken; | ||
| 35 | Bu::Variant vExtra; | ||
| 36 | }; | ||
| 37 | |||
| 38 | virtual Token *nextToken()=0; | ||
| 39 | |||
| 40 | virtual Bu::FString tokenToString( const Token &t ); | ||
| 41 | }; | ||
| 42 | }; | ||
| 43 | |||
| 44 | #endif | ||
