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

  • SEARCH
  • Home
  • 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 7654397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:14:46+00:00 2026-05-31T12:14:46+00:00

I asked a question earlier , but I don’t think I was clear enough

  • 0

I asked a question earlier, but I don’t think I was clear enough about the sort of answers I was hoping for, so let me provide a more concrete example:

class Program
{
    private static bool State;

    static void Main(string[] args)
    {
        State = false;
        Console.WriteLine(And());
        Console.ReadLine();
    }

    static bool And()
    {
        return Or() && C();
    }

    static bool Or()
    {
        return A() || AB();
    }

    static bool C()
    {
        return State;
    }

    static bool A()
    {
        return true;
    }

    static bool AB()
    {
        State = true;
        return true;
    }
}

The flow of this program looks like:

  1. And() gets called
  2. And() calls Or()
  3. Or() calls A()
  4. A() returns true
  5. Flow returns to Or(), which returns true (lazy evaluation)
  6. Flow returns to And(), And() calls C()
  7. C() returns false
  8. Flow returns to And(), which returns false

Now if Or() did not perform lazy evaluation (I change || to |), the program will return true. However, I don’t want AB() to executed unless the result of the entire parse fails (And() returns false).

So what I’d like to do, is somewhere in the Or() function, save the current state on a stack (static variable) so that if And() returns false, I can pop an item off the stack and try the alternative.

How would I accomplish this in C#?

  • 1 1 Answer
  • 0 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-31T12:14:47+00:00Added an answer on May 31, 2026 at 12:14 pm

    It strikes me as being fairly trivial- just rearrange the calls:

    static void Main(string[] args)
    {
        State = false;
        Console.WriteLine(Or());
        Console.ReadLine();
    }
    
    static bool Or()
    {
        return A() && C() || AB() && C();
    }
    

    Or am I missing something? Maybe C() has side effects such that it should not be called twice?

    EDIT: Now I understand what you are trying to do. Do yourself a favor. Listen to the suggestions you’ve gotten, get a copy of GPPG, or (probably much simpler) ANTLR, with ANTLRWorks. It is so, so much easier and less error prone than attempting to roll a parser by hand, and you still get C# at the end.

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

Sidebar

Related Questions

I have asked this question earlier today but I didn't provide enough information and
I asked a similar question earlier in the week but I don't think my
Ok, I asked a question earlier about Flex and ADO.NET Data Services but didn't
You may think this question is like this question asked on StackOverflow earlier. But
I have asked a question earlier but I think I missed the point so
I asked a question earlier today, but I think I need to approach it
In an earlier question, I asked about typecasting pointers, but was directed to the
I asked this question earlier but regarding another programming languages. Let's say I have
I asked a question about this earlier but received no responses, so I'm trying
I asked a simialr question earlier about using jquery and hashtags but what I

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.