diff options
Diffstat (limited to '')
-rw-r--r-- | src/parser.h | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/src/parser.h b/src/parser.h index 26b15a6..e720e54 100644 --- a/src/parser.h +++ b/src/parser.h | |||
@@ -1,8 +1,12 @@ | |||
1 | #ifndef BU_PARSER_H | 1 | #ifndef BU_PARSER_H |
2 | #define BU_PARSER_H | 2 | #define BU_PARSER_H |
3 | 3 | ||
4 | #include "bu/list.h" | ||
5 | #include "bu/fstring.h" | 4 | #include "bu/fstring.h" |
5 | #include "bu/list.h" | ||
6 | #include "bu/array.h" | ||
7 | #include "bu/hash.h" | ||
8 | #include "bu/signals.h" | ||
9 | |||
6 | #include "bu/lexer.h" | 10 | #include "bu/lexer.h" |
7 | 11 | ||
8 | namespace Bu | 12 | namespace Bu |
@@ -35,13 +39,75 @@ namespace Bu | |||
35 | */ | 39 | */ |
36 | void parse(); | 40 | void parse(); |
37 | 41 | ||
42 | void setRootNonTerminal( int iRoot ); | ||
43 | void setRootNonTerminal( const Bu::FString &sRoot ); | ||
44 | |||
45 | typedef Bu::Signal1<void, Parser &> Reduction; | ||
46 | |||
47 | /** | ||
48 | * Represents a possible state, either a terminal or non-terminal symbol | ||
49 | * in a Production. | ||
50 | */ | ||
51 | class State | ||
52 | { | ||
53 | public: | ||
54 | enum Type | ||
55 | { | ||
56 | typeTerminal, | ||
57 | typeTerminalPush, | ||
58 | typeNonTerminal, | ||
59 | typeReduction | ||
60 | }; | ||
61 | |||
62 | State( Type eType, int iIndex ); | ||
63 | virtual ~State(); | ||
64 | |||
65 | private: | ||
66 | Type eType; | ||
67 | int iIndex; | ||
68 | }; | ||
69 | |||
70 | typedef Bu::List<State> Production; | ||
71 | |||
72 | class NonTerminal | ||
73 | { | ||
74 | public: | ||
75 | NonTerminal(); | ||
76 | virtual ~NonTerminal(); | ||
77 | |||
78 | void addProduction( Production p ); | ||
79 | |||
80 | private: | ||
81 | typedef Bu::List<Production> ProductionList; | ||
82 | ProductionList lProduction; | ||
83 | }; | ||
84 | |||
85 | int addNonTerminal( const Bu::FString &sName, NonTerminal &nt ); | ||
86 | int addNonTerminal( const Bu::FString &sName ); | ||
87 | void setNonTerminal( const Bu::FString &sName, NonTerminal &nt ); | ||
88 | int getNonTerminalId( const Bu::FString &sName ); | ||
89 | |||
90 | int addReduction( const Bu::FString &sName, const Reduction &r ); | ||
91 | int addReduction( const Bu::FString &sName ); | ||
92 | void setReduction( const Bu::FString &sName, const Reduction &r ); | ||
93 | int getReductionId( const Bu::FString &sName ); | ||
94 | |||
38 | private: | 95 | private: |
39 | typedef Bu::List<Lexer *> LexerStack; | 96 | typedef Bu::List<Lexer *> LexerStack; |
40 | typedef Bu::List<Lexer::Token *> TokenStack; | 97 | typedef Bu::List<Lexer::Token *> TokenStack; |
41 | typedef Bu::List<State *> StateStack; | 98 | typedef Bu::List<Production::const_iterator> StateStack; |
99 | typedef Bu::Array<Reduction> ReductionArray; | ||
100 | typedef Bu::Hash<Bu::FString,int> NameIndexHash; | ||
101 | typedef Bu::Array<NonTerminal> NonTerminalArray; | ||
102 | |||
42 | LexerStack sLexer; | 103 | LexerStack sLexer; |
43 | TokenStack sToken; | 104 | TokenStack sToken; |
44 | StateStack sState; | 105 | StateStack sState; |
106 | ReductionArray aReduction; | ||
107 | NameIndexHash hReductionName; | ||
108 | NonTerminalArray aNonTerminal; | ||
109 | NameIndexHash hNonTerminalName; | ||
110 | int iRootNonTerminal; | ||
45 | }; | 111 | }; |
46 | }; | 112 | }; |
47 | 113 | ||