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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:44:27+00:00 2026-06-15T01:44:27+00:00

So I have been assigned this project and have been giving it the old

  • 0

So I have been assigned this project and have been giving it the old college try but I am a little lost on how to go about it. The idea is you’re given a txt file with a grammar in the form:

  • V: S, A, B, C
  • T: a, b
  • S: S
  • P:
  • S -> aAaA|aABBA
  • A -> AaaA|$
  • B -> bB|bbC
  • C -> B

These productions rules won’t be the only ones tested but that’s just an example.

So the first step is to read in the program.
The next step is to remove Lambda ($) productions.
and the final step is to remove unit productions.

I am … the way I’m removing lambda productions is not the best way I think.

Here’s how I’m doing it.

So first, use getline to read in the file.
Next use some loops to go through a file.

Now in an array, I’ve stored the non terminals that correspond to a rule with a lambda production, so keep that in mind.

So, while going through each character in each production, check if that character is the same as one in the array of the non terminals that denote lambda productions (excluding the index 0 because that’s the start of the production)

if you find a match, mark that index you’re on

so say your going through S.

S -> a (no problem)
s -> aA (Ok a bit of a problem)

instead of writing the A, don’t. skip over it and then using another loop, print out the remaining chunk of that production rule (that is, print out until you hit a bar)
so we get
S -> aaA

now draw a bar

S -> aaA|
now return the index to the first character in this chunk, here being a. From there, rewrite the character up through where you first hit the non terminal.

S -> aaA|aA

now continue looping through to find the next non terminal that’s a lambda

S -> aaA | aAaA (here we are)

draw a bar

S -> aaA | aAa |

move back to beginning, continue through

S -> aaA | aAa | aAaA

continue reading through the grammar and outputing each characters and repeat this process to get

S -> aaA | aAa | aAaA | aABB | aBBA | aABBA

at the end of all the code, I have two loops that check for the original bars in the grammar (i replace them with !’s when I did it) and then output at the end the form that has all lambda productions as lambdas giving

S -> aaA | aAa | aAaA | aa | aABB | aBBA | aABBA | aBB

I’m going to include the code here but, be warned,… it’s rough. It’s rough enough that I can’t actually get it to fall nicely under the codeing blocks in here so i’m going link it.

Code

I appreciate any ideas on how you would undertake this project or if i’m doing something blatantly wrong.

The code currently throws out some errors (which i’m pretty sure are the cause of me reading some empty characters somewhere) but if you ignore them it’ll spit out to console the right thing… mostly.

Appreciate any help, thank you for taking the time to read all this mess.

  • 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-15T01:44:28+00:00Added an answer on June 15, 2026 at 1:44 am

    Here is the architecture I would recommend:

    1. Define the metagrammar of the grammar (the syntax of the grammar productions you are using)
    2. Write a simple tokenizer for that metagrammar
    3. Write a handwritten recursive decent parser based on metagrammar to parse and create a syntax tree for each input grammar production
    4. Manipulate the syntax trees according the CNF rules
    5. Generate the output from the modified syntax trees.

    Example meta grammar:

    production:
        nonterminal ':' alternatives
    
    alternatives:
        alternative,
        alternative ',' alternatives
    
    alternative:
        symbols
    
    symbols:
        symbol,
        symbol symbols
    
    symbol:
        terminal,
        nonterminal,
        '$'
    
    etc..
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure this little section of my larger project out
hey friends, i have been assigned a query planning project. in this project if
I have been assigned a new project to do some enhancements, but while compiling
Recently I've been assigned to a project where we have to migrate an old
I have been assigned to Convert a VB.NET project to C# and I got
I need some help with a work project I have been assigned. At the
I have recently been assigned a CSS & design project that's in a CakePHP
I have been assigned to work on a Java/Flash/BlazeDS project. When I pull down
I found a bunch of scripts in the project I have been newly assigned
I've been assigned to a new project. I have to maintain an application which

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.