Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 911585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:13:57+00:00 2026-05-15T17:13:57+00:00

I would like to implement a FSM/pushdown automaton parser for this syntax: parser with

  • 0

I would like to implement a FSM/”pushdown automaton” parser for this syntax: parser with scopes and conditionals which has already been “lexed” into 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!

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:13:58+00:00Added an answer on May 15, 2026 at 5:13 pm

    Feel free to still post your take on this, but I have figured out how to handle everything gracefully:

    First: my event loop will keep a pointer to the last State* created.

    Second: Each State has a pointer to the parent State, initialized in the constructor, defaulting to 0 (memory leak if used for anything but the first State*); this guarantees that no State will go out of scope.

    Third: State* endOfState() function which does exactly this (and I’m particularly proud of this.

    State* State::endOfState()
    {
        State* parent = m_parent; // keep member pointer after suicide
        delete this;
        return parent;
    }
    

    When this is called from within a subclass’s event(), it will properly delete itself, and return the parent pointer (going one up in the ladder).

    If this still contains a leak, please inform me. If the solution is not clear, please ask 🙂

    PS: for all fairness, inspiration was stolen from http://www.codeguru.com/forum/showthread.php?t=179284

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 451k
  • Answers 451k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yours should work just fine (you edited it in after… May 15, 2026 at 8:58 pm
  • Editorial Team
    Editorial Team added an answer You really need to understand how the Muenchian grouping works,… May 15, 2026 at 8:58 pm
  • Editorial Team
    Editorial Team added an answer Give permission to the "Approved" workflow state. May 15, 2026 at 8:58 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.