Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that does the following: 1. Reads a grammar. 2. Finds the canon ical LR (0) sets INPUT: A grammar G OUTPUT: The
Write a program that does the following: 1. Reads a grammar. 2. Finds the canon ical LR (0) sets INPUT: A grammar G OUTPUT: The list of all productions in G The canon ical LR (0) collection of sets for G In addition to numbering the sets, as done in the text, identify the symbol X that generates the s et through the function GOTO(I,X) DELIVERABLES: Program source code with internal documentation Test results for grammar G419 and at least one other grammar. HINT: Modify your Lab 4 p rogram for this exercise The routines to input and print the grammar are the same and the data structure to hold the items is the same as the data structure to hold a production, with a single added data item to indicate the position of the dot in the right hand side. If you leave the routines for FIRST and FOLLOW as part of the program, even though you do not use them in this exercise, the resulting code contains most of the ingredients you need to produce an SLR parser ALGORITHMS: You will need the algorithms for CLOSURE (pg. 222) and GOTO (pg. 224) The algorithms are recursive, they start from the unique production that contains the start symbol of an extended grammar. As described in section 4.7 in the text alternately apply CLOSU and GoTO until nothing more RE can be done. Note that CLOSURE (I) fills out sets, GOTO(I,X) may add new sets of items to the collection Write a program that does the following: 1. Reads a grammar. 2. Finds the canon ical LR (0) sets INPUT: A grammar G OUTPUT: The list of all productions in G The canon ical LR (0) collection of sets for G In addition to numbering the sets, as done in the text, identify the symbol X that generates the s et through the function GOTO(I,X) DELIVERABLES: Program source code with internal documentation Test results for grammar G419 and at least one other grammar. HINT: Modify your Lab 4 p rogram for this exercise The routines to input and print the grammar are the same and the data structure to hold the items is the same as the data structure to hold a production, with a single added data item to indicate the position of the dot in the right hand side. If you leave the routines for FIRST and FOLLOW as part of the program, even though you do not use them in this exercise, the resulting code contains most of the ingredients you need to produce an SLR parser ALGORITHMS: You will need the algorithms for CLOSURE (pg. 222) and GOTO (pg. 224) The algorithms are recursive, they start from the unique production that contains the start symbol of an extended grammar. As described in section 4.7 in the text alternately apply CLOSU and GoTO until nothing more RE can be done. Note that CLOSURE (I) fills out sets, GOTO(I,X) may add new sets of items to the collection
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started