Question: Compiler Construction-Recursive descent parser Single source code in c++ . Create a recursive descent parser as per the code in lecture 14 for the following
Compiler Construction-Recursive descent parser
Single source code in c++ .Create a recursive descent parser as per the code in lecture 14 for the following grammar
CODE IN LECTURE:
#include#include #include using namespace std; int ch; void error(char *msg){ printf("Error - found character %c - %s ",ch,msg); exit(1); } void b(){ if (ch=='y') ch = getchar(); else error("y expected "); } void a(){ if(ch=='x'){ ch = getchar(); a(); } else b(); } void s(){ if (ch=='z') ch = getchar(); else{ a(); if (ch!='z') error("z expected "); else ch = getchar(); } printf("success! "); } int main(int argc,char *argv[]) { ch=getchar(); s(); return 0; }
//////////////////////////////////////////////////////////////////////////////
For your reference, this is the original grammar, that had to be modified so the recursive descent parser would be able to handle :
E-> E + T | T
T-> T* F | F
F-> ( E ) | id
Prepare input by hand in the following format
Actual input line
Tokens extracted by hand, one per line
For example:

For the code example during the lecture, a grammar was used where each terminal and each non-terminal was a single character
S-> Az|z
A->xA|B
B->y
///////////
-For the grammar you have for the assignment, you have multi-character symbols for both So string handling will be required instead of just character handling
Your parser should print out either
-Parsed successfully
-Failed
ETE E+TE TFT TFT F(E)id \begin{tabular}{l} \hlinex+yz \\ id \\ + \\ id \\ \\ id \end{tabular}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
