aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-10-12 07:35:08 +0000
committerMike Buland <eichlan@xagasoft.com>2010-10-12 07:35:08 +0000
commit0981b9d6a12bd7aadbf9286459e033ac1a2ba910 (patch)
treefa461761086f182e43f94637a9c8df040333e8a4 /src/tools
parent1ee5f374ed986333d5cdbbf41390f1c4c755a8e3 (diff)
downloadlibbu++-0981b9d6a12bd7aadbf9286459e033ac1a2ba910.tar.gz
libbu++-0981b9d6a12bd7aadbf9286459e033ac1a2ba910.tar.bz2
libbu++-0981b9d6a12bd7aadbf9286459e033ac1a2ba910.tar.xz
libbu++-0981b9d6a12bd7aadbf9286459e033ac1a2ba910.zip
Ok, libbu++ compiles again, the basic parser system is getting there, I think,
it's still a little tricky becasue you have to do the non-terminal prime seperation yourself (I forget what it's really called), but it's going quite well. After a few tweaks to the core of it, we should be able to do some math :)
Diffstat (limited to '')
-rw-r--r--src/tools/parser.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/tools/parser.cpp b/src/tools/parser.cpp
index a70dfa4..e4fc95f 100644
--- a/src/tools/parser.cpp
+++ b/src/tools/parser.cpp
@@ -149,12 +149,91 @@ private:
149 QueueBuf qbIn; 149 QueueBuf qbIn;
150}; 150};
151 151
152void redAdd( Bu::Parser &p )
153{
154}
155
156void redPrint( Bu::Parser &p )
157{
158}
159
152int main( int argc, char *argv[] ) 160int main( int argc, char *argv[] )
153{ 161{
154 File fIn( argv[1], File::Read ); 162 File fIn( argv[1], File::Read );
155 163
156 Parser p; 164 Parser p;
157 165
166 {
167 Parser::NonTerminal nt;
168 int iSelf = p.addNonTerminal("expr");
169 nt.addProduction(
170 Parser::Production(
171 Parser::State(
172 Parser::State::typeTerminal,
173 tokPlus
174 )
175 ).append(
176 Parser::State(
177 Parser::State::typeNonTerminal,
178 iSelf
179 )
180 ).append(
181 Parser::State(
182 Parser::State::typeReduction,
183 p.addReduction("add")
184 )
185 )
186 );
187 nt.addProduction(
188 Parser::Production()
189 );
190 p.addNonTerminal( "expr", nt );
191 }
192 {
193 Parser::NonTerminal nt;
194 nt.addProduction(
195 Parser::Production(
196 Parser::State(
197 Parser::State::typeTerminalPush,
198 tokNumber
199 )
200 ).append(
201 Parser::State(
202 Parser::State::typeNonTerminal,
203 p.getNonTerminalId("expr")
204 )
205 )
206 );
207 p.addNonTerminal( "expr'", nt );
208 }
209 {
210 Parser::NonTerminal nt;
211 nt.addProduction(
212 Parser::Production(
213 Parser::State(
214 Parser::State::typeNonTerminal,
215 p.getNonTerminalId("expr'")
216 )
217 ).append(
218 Parser::State(
219 Parser::State::typeTerminal,
220 tokCompute
221 )
222 ).append(
223 Parser::State(
224 Parser::State::typeReduction,
225 p.addReduction("print")
226 )
227 )
228 );
229 p.addNonTerminal("input", nt );
230 }
231
232 p.setRootNonTerminal("input");
233
234 p.setReduction("add", Bu::slot( &redAdd ) );
235 p.setReduction("print", Bu::slot( &redPrint ) );
236
158 p.pushLexer( new MathLexer( fIn ) ); 237 p.pushLexer( new MathLexer( fIn ) );
159 238
160 p.parse(); 239 p.parse();