From 0981b9d6a12bd7aadbf9286459e033ac1a2ba910 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 12 Oct 2010 07:35:08 +0000 Subject: 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 :) --- src/tools/parser.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'src/tools/parser.cpp') 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: QueueBuf qbIn; }; +void redAdd( Bu::Parser &p ) +{ +} + +void redPrint( Bu::Parser &p ) +{ +} + int main( int argc, char *argv[] ) { File fIn( argv[1], File::Read ); Parser p; + { + Parser::NonTerminal nt; + int iSelf = p.addNonTerminal("expr"); + nt.addProduction( + Parser::Production( + Parser::State( + Parser::State::typeTerminal, + tokPlus + ) + ).append( + Parser::State( + Parser::State::typeNonTerminal, + iSelf + ) + ).append( + Parser::State( + Parser::State::typeReduction, + p.addReduction("add") + ) + ) + ); + nt.addProduction( + Parser::Production() + ); + p.addNonTerminal( "expr", nt ); + } + { + Parser::NonTerminal nt; + nt.addProduction( + Parser::Production( + Parser::State( + Parser::State::typeTerminalPush, + tokNumber + ) + ).append( + Parser::State( + Parser::State::typeNonTerminal, + p.getNonTerminalId("expr") + ) + ) + ); + p.addNonTerminal( "expr'", nt ); + } + { + Parser::NonTerminal nt; + nt.addProduction( + Parser::Production( + Parser::State( + Parser::State::typeNonTerminal, + p.getNonTerminalId("expr'") + ) + ).append( + Parser::State( + Parser::State::typeTerminal, + tokCompute + ) + ).append( + Parser::State( + Parser::State::typeReduction, + p.addReduction("print") + ) + ) + ); + p.addNonTerminal("input", nt ); + } + + p.setRootNonTerminal("input"); + + p.setReduction("add", Bu::slot( &redAdd ) ); + p.setReduction("print", Bu::slot( &redPrint ) ); + p.pushLexer( new MathLexer( fIn ) ); p.parse(); -- cgit v1.2.3