Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can some expert fix the coding at the very last by following the below questions please!! The given grammar was: P PL | L L

Can some expert fix the coding at the very last by following the below questions please!!

The given grammar was:

P PL | L L N; | M; | C N print E M print "W" W TW | C if E {P} | if E {P} else {P} E (EOE) | V (note: this has a variable O) O + | - | * V 0 | 1 | 2 | 3 (note: this has a terminal 0 (zero)) T a | b | c | d

And the grammar transformed in LL(1) is:

image text in transcribed

5.1 Parsing strings with an LL(1) table driven parser

Implement a program which parses strings using an LL(1) table driven parser using the table you determined for G in the previous exercise.

You may use Python, Java, C, C++, or Haskell. If youd like to use a different language then please check with us first.

Input: The first command line argument is the filename of a file containing the string of characters to test.

Output: 1. Print a trace of the execution, showing the steps followed by the program as it performs the left-most derivation. This should look similar to parsing the string through a PDA. An example of this is given in the appendices.

2. After parsing the whole input file, print ACCEPTED or REJECTED, depending on whether or not the string could be derived by the grammar.

3. If there is a symbol in the input string which is not a terminal from the grammar, the program should output ERROR_INVALID_SYMBOL (This could be during or before trying to parse the input.) Note: all whitespace in the input file should be ignored (line breaks, spaces, etc.) The output will be easier to read if you remove the whitespace before starting the parse. Examples of the program output syntax are provided in the appendices.

5.2 Evaluating programs written in G

If a second command line argument eval is given, then instead of printing the trace of the parse, your program should:

1. Build a parse tree as it performs the leftmost derivation

2. Evaluate that parse tree. The semantics (meaning) which we are applying to our rules are as follows:

V variables derive integers W variables derive strings E expressions are evaluated like normal integer arithmetic

print E statements output (to screen) the result of evaluating the expression E. (i.e. print (1+1) outputs 2)

print "W" statements output the string derived from W (i.e. print "abba" outputs abba)

if statements evaluate the contents of their if block if and only if the condition evaluated to a non-zero value, otherwise the else block is evaluated instead (if there is one). If the input could not be parsed then output REJECTED instead. Some examples of programs and their expected output are provided in the appendices.

image text in transcribed

image text in transcribed

The codes are:

#include  #include  #include  #include  #include  void main() { clrscr(); int i=0,j=0,k=0,m=0,n=0,o=0,o1=0,var=0,l=0,f=0,c=0,f1=0; char str[30],str1[40]="E",temp[20],temp1[20],temp2[20],tt[20],t3[20]; strcpy(temp1,'\0'); strcpy(temp2,'\0'); char t[10]; char array[6][5][10] = { "NT", "","+","*",";", "E", "Te","Error","Error","Error", "e", "Error","+Te","Error","\0", "T", "Vt","Error","Error","Error", "t", "Error","\0","*Vt","\0", "V", "","Error","Error","Error" }; cout =strlen(str)) { getch(); exit(1); } for(int l=1;l  1. T all clad V 0 1 2 3 E CEOE) C' else (P) E 8, N' print M 10, L N IC 12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

Working with other project stakeholders for support.

Answered: 1 week ago

Question

Knowledge of project management (PMI) teachings

Answered: 1 week ago