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 9294133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:17:59+00:00 2026-06-18T21:17:59+00:00

This is my first question , please correct me if anything is wrong. I

  • 0

This is my first question , please correct me if anything is wrong.
I have some set of old rules in one of document system , im trying to convert them into new document system.
I have lot of IF-ENDIF and IF-ELSE-ENDIF nested inside each other like below. Need some logic which works on converting below input to corresponding output.
Need help for algo. Thanks

INPUT:  
IF (Cond 1)  
    IF(Cond 2)  
    ENDIF  
    IF(Cond3)  
    ELSE  
    ENDIF  
ELSE  
    IF(Cond4)  
    ELSE  
        IF(Cond5)  
        ELSE  
        ENDIF  
    ENDIF  
    IF(Cond6)  
    ENDIF  
ENDIF  

Required OUTPUT:

    IF(Cond1) AND (Cond2)  
    IF(Cond1) AND (Cond3)  
    IF(Cond1) AND !(Cond3)  
    IF!(Cond1) AND (Cond4)  
    IF!(Cond1) AND !(Cond4)  AND (Cond5)  
    IF!(Cond1) AND !(Cond4) AND !(Cond5)  
    IF!(Cond1) AND (Cond6)  
  • 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-06-18T21:18:00+00:00Added an answer on June 18, 2026 at 9:18 pm

    I will assume that you have logic that can parse the file in the first place. If so, then you should end up with an abstract syntax tree where each node looks something like this:

    If
      |
      +--- Condition
      |
      +--- Positive statement
      |
      +--- Negative statement
    

    or

    Sequence
      |
      +--- Statement 1
      |
      +--- Statement 2
      |
      ...
      |
      +--- Statement n
    

    or

    Terminal
    

    where Terminal represents a concrete statement. They are implicit in your original input file. For example, “IF(COND2) ENDIF” would be represented as follows:

    If
      |
      +--- Cond2
      |
      +--- Terminal
      |
      +--- (null)
    

    In your case, your actual tree would look something like this:

    If
      |
      +--- Cond1
      |
      +--- Sequence
      |      |
      |      +--- If
      |      |      |
      |      |      +--- Cond2
      |      |      |
      |      |      +--- Terminal
      |      |      |
      |      |      +--- (null)
      |      |
      |      +--- If
      |             |
      |             +--- Cond3
      |             |
      |             +--- Terminal
      |             |
      |             +--- Terminal
      |
      +--- If
           ...
    

    To generate the output, you would simply recursively walk down the tree, building a stack of conditions along the way, then when you get to a statement, output the whole stack of conditions with ANDs between them. Here is some pseudocode:

    void treeWalk(root):
        treeWalk(root, []);
    
    void treeWalk(root, conditions):
        case root of:
            If(cond, positive, negative):
                if (positive is not null):
                    treeWalk(positive, conditions + cond)
                if (negative is not null):
                    treeWalk(negative, conditions + !cond)
            Sequence(statements):
                for each statement in statements:
                    treeWalk(statements, conditions)
            Terminal:
                print "IF "
                for each condition in conditions:
                    if (condition is not the last condition):
                        print " AND "
                    print condition
    

    Here I am using + to indicate appending an item to a list. It is assumed that !cond results in a condition that prints itself out with a “!” at the front.

    I hope that helps!

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

Sidebar

Related Questions

this is my first question :) I have one pile file, and I have
This is my first question, so please be gentle. I'm trying out Apache Camel
This is my first post on stackoverflow, so please excuse me if my question
this is my first question I have searched for any launching activity questions and
this is my first question on stack overflow. Some quick background, this is not
This is my first question on Stack Overflow. Please be kind on my mistakes.
This is my first ever question on SO. So I have a MYSQL table
this is my first question in here, and I would like to ask if
This is my first question on Stack Overflow, so I hope that I'm clear
this is my first question to SO so i'll try not to disgrace myself.

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.