Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
What you need to do:
1. Type that code up and run it to make sure that it is doing what it is supposed to
do. Provide the strings in the header of the program when prompted.
2. Use the logic in that program to design your own Recursive Descent parser in C
for the following grammar:
S →aAB
A →Abc | b
B →d
3. Make sure that you choose at least two strings that pass the grammar and one
string that does not pass the grammar just like I did in the model program
4. Submit both the code and a screen shot of your results for the choice of strings
that you provided.
Below is the C code that can be used to implement a Recursive Descent parser for the above
grammar
/* Recursive Descent Parser for the Expression Grammar:
S → (L) |a
L' →,SL'|ε
L → SL'
Valid inputs: (a,(a,a)) and (a,((a,a),(a,a)))
Invalid inputs:(aa,a)
*/
#include <stdio.h>
#include <string.h>
int S(), Ldash(), L();
char *ip;
char string[50];
int main()
grammar
/* Recursive Descent Parser for the Expression Grammar:
S → (L) |a
L' →,SL'|ε
L → SL'
Valid inputs: (a,(a,a)) and (a,((a,a),(a,a)))
Invalid inputs:(aa,a)
*/
#include <stdio.h>
#include <string.h>
int S(), Ldash(), L();
char *ip;
char string[50];
int main()
{
printf("Enter the string\n");
scanf("%s", string);
ip = string;
printf("\n\nInput\t\tAction\n ------------------------------\n");
if (S())
{
printf("\n------------------------------------------------\n");
printf("\n String is successfully parsed\n");
}
else
{
printf("\n ------------------------------------------------\n");
printf("Error in parsing string\n");
}
}
int L()
{
printf("%s\t\tL →SL' \n", ip);
if (S())
{
if (Ldash())
{
return 1;
}
else
return 0;
}
else
return 0;
}
int Ldash()
{
if (*ip == ',')
{
printf("%s\t\tL' →, SL' \n", ip);
ip++;
if (S())
{
if (Ldash())
{
return 1;
}
else
return 0;
}
else
printf("Enter the string\n");
scanf("%s", string);
ip = string;
printf("\n\nInput\t\tAction\n ------------------------------\n");
if (S())
{
printf("\n------------------------------------------------\n");
printf("\n String is successfully parsed\n");
}
else
{
printf("\n ------------------------------------------------\n");
printf("Error in parsing string\n");
}
}
int L()
{
printf("%s\t\tL →SL' \n", ip);
if (S())
{
if (Ldash())
{
return 1;
}
else
return 0;
}
else
return 0;
}
int Ldash()
{
if (*ip == ',')
{
printf("%s\t\tL' →, SL' \n", ip);
ip++;
if (S())
{
if (Ldash())
{
return 1;
}
else
return 0;
}
else
return 0;
}
else
{
printf("%s\t\tL' →ε \n", ip);
return 1;
}
}
int S()
{
if (*ip == '(')
{
printf("%s\t\tS →(L) \n", ip);
ip++;
if (L())
{
if (*ip == ')')
{
ip++;
return 1;
}
else
return 0;
}
else
return 0;
}
else if (*ip == 'a')
{
ip++;
printf("%s\t\tS →a \n", ip);
return 1;
}
else
return 0;
}
}
else
{
printf("%s\t\tL' →ε \n", ip);
return 1;
}
}
int S()
{
if (*ip == '(')
{
printf("%s\t\tS →(L) \n", ip);
ip++;
if (L())
{
if (*ip == ')')
{
ip++;
return 1;
}
else
return 0;
}
else
return 0;
}
else if (*ip == 'a')
{
ip++;
printf("%s\t\tS →a \n", ip);
return 1;
}
else
return 0;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- What is the process that begins with the start symbol of a grammar, performs productions, and ends with an unexpandable string?arrow_forwardWhich of the following is true about bottom-up parsers? a.Input is processed from right to left b.Grammar must be free of left recursion c.Left recursion is not a problem d.Input is processed left to right in reverse orderarrow_forwardSelect all the correct statements about lists in Prolog Select one or more: a. [] is the empty list b. [a,b,c] can be represented as [H|T] where H is unified to a and T is unified to [b,c] c. [a,b,c] can be represented as [H|T] where H is unified to [a] and T is unified to [b,c] d. [[a,b,c],[a,d],d] can be represented as [H|T] where H is unified to a and T is unified to [[b,c],[a,d],d] e. [[a,b,c],[a,d],d] can be represented as [H|T] where H is unified to a and T is unified to [[b,c,a,d],d]arrow_forward
- Please help 8. The known Grammar as follows: S à AX X à or AX | ️(epsilon) A à CY Y à and CY | ️(epsilon) C à not C | (S) | 0 | 1 Question C. Please do a stack implementation for strings: (0 or 1) and 1arrow_forwardUse the logic in the program below S →aABA →Abc | bB →d choose at least two strings that pass the grammar and onestring that does not pass the grammararrow_forwardThe next 3 questions pertain to the following grammar from the book. The string to test is aba. S→ XY X→ XA | a | b Y→AY|a A→ a Question 1 Enter which variables can generate the following substrings of length 2 as found in stage 2 of the CYK algorithm. Enter no spaces. Enter multiple variables separated by a comma in alphabetical order (e.g., XY). If there are no variables that generate the substring, enter none. ab e ba e Question 2 Enter which variables can generate the following substrings of length 3 as found in stage 3 of the CYK algorithm. Enter no spaces. Enter multiple variables separated by a comma in alphabetical order (e.g., X,Y). If there are no variables that generate the substring, enter none. a ba e ab a +arrow_forward
- What is the name of the operation that begins with the start symbol of a grammar, runs many productions, and finishes with a string that cannot be expanded further?arrow_forwardWhat language does the following grammar generate? Use set notation, English or regular expression to describe it. S->bA | b A->abA | abSarrow_forwardThe following YACC snippet is used to implement a grammar of an expression. The expressions are : E-> E +E E-> E'E E-> id program: program expr '\n' { printf("Kd\n", S2); ) expr: { SS - $1; } i ss - s1- $3; } { $S - $1 - $3; } INTEGER I expr + expr I expr expr Modify the above code to handle the following grammar rules: E-> Add EE E -> Sub EE E-> Mul EE E-> Div EE E-> id, where Add, Sub, Mul, and Div are used to implement Addition, subtraction, multiplication, and division operations respectively.arrow_forward
- d. Write a Lisp program that verifies if a list of symbols is correct from the point of view of this grammar. For example, (check-A '(y w z w y)) (check-A '(y z w w)) should return true (t) and should return false (nil).arrow_forwardTalk about where a grammar mistake could happen during the process of processing.arrow_forwardCan you show Grammar for expressions consisting of digits and plus and minus signs?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education