Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Given the grammar below: 1. A id = E 2. EE +T EE-T T 3. TT*F T/F F 4. F (E) i

ID: 3694867 • Letter: 4

Question

4. Given the grammar below: 1.   A id = E 2. EE +T EE-T T 3. TT*F T/F F 4. F (E) id 5. id a bc………..z etc
             Write a program for the bottom up parsing algorithm of the following input strings
a. a= b+c –d b. a= b*c + d*e c. a=b*c*d d. a=a/b –c*d e. a=b+c –d –f
           For now, you need to hand generate the handle sequences of the above strings and use them as inputs to your program.
5. Repeat NO. 4 but this time you need to hand generate the DFA for the above grammar and complete the bottom up parsing algorithm for the above strings (extra credit, attempt only after completed others)
6.   Using the concepts of syntax directed translation, write a program to build the binary tree for the above strings in NO. 4
7. Also using syntax directed translation concept discussed in class, generate the three address codes for the strings in NO. 4

Explanation / Answer

# include # include # include staticchar Stack[50][10]={NULL}; staticint top=-1; staticint cit=0; // Input Grammarstaticint productions[6]={5,1,7,7,2,10}; constchar Grammar[5][11][10]={ {"S","E"}, {"E","E+T","E-T","E*T","E/T","E%T","E^T","T"}, {"T","T+F","T-F","T*F","T/F","T%F","T^F","F"}, {"F","(E)","D"}, {"D","0","1","2","3","4","5","6","7","8","9"} }; // Input Statementconstint input_length=8; char Input[input_length][5]={"2","*","(","3","+","4",")","$"}; /*************************************************************************///------------------------------ Push( ) ------------------------------///*************************************************************************/void Push(constchar* Token) { top++; strcpy(Stack[top],Token); } /*************************************************************************///------------------------------- Pop( ) ------------------------------///*************************************************************************/void Pop( ) { strset(Stack[top],NULL); top--; } /*************************************************************************///----------------------------- Reduce( ) -----------------------------///*************************************************************************/void Reduce(constint items,constint index) { for(int i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote