aboutsummaryrefslogtreecommitdiff
path: root/src/parser.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-10-12 06:09:48 +0000
committerMike Buland <eichlan@xagasoft.com>2010-10-12 06:09:48 +0000
commit1ee5f374ed986333d5cdbbf41390f1c4c755a8e3 (patch)
tree67b02598d3dca87a82263629a1290bd7b7a79006 /src/parser.h
parent313e28df2a8776c82f5493aef6fe44ad40f1935a (diff)
downloadlibbu++-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.h')
-rw-r--r--src/parser.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/parser.h b/src/parser.h
new file mode 100644
index 0000000..26b15a6
--- /dev/null
+++ b/src/parser.h
@@ -0,0 +1,48 @@
1#ifndef BU_PARSER_H
2#define BU_PARSER_H
3
4#include "bu/list.h"
5#include "bu/fstring.h"
6#include "bu/lexer.h"
7
8namespace Bu
9{
10 /**
11 * The base framework for a LR(1) grammar parser. Provided a proper set of
12 * ParserStates this will prase any input the lexer can provide.
13 */
14 class Parser
15 {
16 public:
17 Parser();
18 virtual ~Parser();
19
20 /**
21 * When a Lexer is pushed onto the stack it becomes the source for
22 * future tokens read by the parser until it is popped off the stack.
23 * The Parser takes ownership of every Lexer pushed onto the stack,
24 * and will delete it when it is popped off the stack.
25 */
26 void pushLexer( Lexer *pLex );
27
28 /**
29 * Pop a lexer off the stack, and delete it.
30 */
31 void popLexer();
32
33 /**
34 * Execute a parse.
35 */
36 void parse();
37
38 private:
39 typedef Bu::List<Lexer *> LexerStack;
40 typedef Bu::List<Lexer::Token *> TokenStack;
41 typedef Bu::List<State *> StateStack;
42 LexerStack sLexer;
43 TokenStack sToken;
44 StateStack sState;
45 };
46};
47
48#endif