Hi,
I would like to implement a FSM/"pushdown automaton" parser for this syntax: http://stackoverflow.com/questions/3025293/c-general-parser-with-scopes-and-conditionals which has already been "lexed" into http://stackoverflow.com/questions/3085070/finite-state-machine-parser
I have the following:
class State
{
public:
virtual State* event( const string &token );
State* deleteDaughter();
private:
A* m_parent;
A* m_daughter;
}
class SomeState : public State
{
public:
State* event( const std::string &token );
}
With B
's event()
doing (after many if-elseif's) return m_parent->deleteDaughter()
. I know this is fishy (and it crashes), but I need way to return the parent State
from the daughter State
and make sure the daughter State
isn't leaked.
My event loop looks like this:
while( somestringstream >> token )
state = state->event();
Before you scold the design and last piece of code, I tried extending a much too simple example from here, which seems pretty ok. I am moving the decision part to the states themselves, for clarity and brevity.
I understand there's loads of books on this subject, but I'm no computer scientist/programmer and I want to learn to do this myself (of course, with the help of all the friendly people at SO). If the concept isn't clear, please ask. Thanks!