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/parser.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) (limited to 'src/parser.h') 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 @@ #ifndef BU_PARSER_H #define BU_PARSER_H -#include "bu/list.h" #include "bu/fstring.h" +#include "bu/list.h" +#include "bu/array.h" +#include "bu/hash.h" +#include "bu/signals.h" + #include "bu/lexer.h" namespace Bu @@ -35,13 +39,75 @@ namespace Bu */ void parse(); + void setRootNonTerminal( int iRoot ); + void setRootNonTerminal( const Bu::FString &sRoot ); + + typedef Bu::Signal1 Reduction; + + /** + * Represents a possible state, either a terminal or non-terminal symbol + * in a Production. + */ + class State + { + public: + enum Type + { + typeTerminal, + typeTerminalPush, + typeNonTerminal, + typeReduction + }; + + State( Type eType, int iIndex ); + virtual ~State(); + + private: + Type eType; + int iIndex; + }; + + typedef Bu::List Production; + + class NonTerminal + { + public: + NonTerminal(); + virtual ~NonTerminal(); + + void addProduction( Production p ); + + private: + typedef Bu::List ProductionList; + ProductionList lProduction; + }; + + int addNonTerminal( const Bu::FString &sName, NonTerminal &nt ); + int addNonTerminal( const Bu::FString &sName ); + void setNonTerminal( const Bu::FString &sName, NonTerminal &nt ); + int getNonTerminalId( const Bu::FString &sName ); + + int addReduction( const Bu::FString &sName, const Reduction &r ); + int addReduction( const Bu::FString &sName ); + void setReduction( const Bu::FString &sName, const Reduction &r ); + int getReductionId( const Bu::FString &sName ); + private: typedef Bu::List LexerStack; typedef Bu::List TokenStack; - typedef Bu::List StateStack; + typedef Bu::List StateStack; + typedef Bu::Array ReductionArray; + typedef Bu::Hash NameIndexHash; + typedef Bu::Array NonTerminalArray; + LexerStack sLexer; TokenStack sToken; StateStack sState; + ReductionArray aReduction; + NameIndexHash hReductionName; + NonTerminalArray aNonTerminal; + NameIndexHash hNonTerminalName; + int iRootNonTerminal; }; }; -- cgit v1.2.3