Question: Please fix the problem for below JAVA code, when i enter ( a + a ) $ as input I get invalid output which is
Please fix the problem for below JAVA code, when i enter aa $ as input I get invalid output which is not correct:
import java.util.;
public class Project
private static final Map parsingTable new HashMap;
private static final Set terminals new HashSetArraysasLista$;
private static final Set nonTerminals new HashSetArraysasListEQTRF;
static
Map eRow new HashMap;
eRow.putTQ;
eRow.putaTQ;
parsingTable.putE eRow;
Map qRow new HashMap;
qRow.putTQ;
qRow.putTQ;
qRow.put;
qRow.put$;
parsingTable.putQ qRow;
Map tRow new HashMap;
tRow.putFR;
tRow.putaFR;
parsingTable.putT tRow;
Map rRow new HashMap;
rRow.put;
rRow.put;
rRow.putFR;
rRow.putFR;
rRow.put;
rRow.put$;
parsingTable.putR rRow;
Map fRow new HashMap;
fRow.putE;
fRow.putaa;
parsingTable.putF fRow;
public static void mainString args
Scanner scanner new ScannerSystemin;
System.out.printlnEnter the input string ending with $:;
String input scanner.nextLine;
scanner.close;
if parseinput
System.out.printlnOutput: String is acceptedvalid;
else
System.out.printlnOutput: String is not acceptedinvalid;
private static boolean parseString input
Stack stack new Stack;
stack.push$;
stack.pushE;
int index ;
while index input.length
char currentChar input.charAtindex;
if terminals.containscurrentChar && currentChar
System.out.printlnInvalid character in the input string.";
return false;
char top stack.peek;
if top currentChar
stack.pop;
index;
else if nonTerminalscontainstop
stack.pop;
if parsingTablecontainsKeytop && parsingTable.gettopcontainsKeycurrentChar
String production parsingTable.gettopgetcurrentChar;
for int i production.length; i ; i
char prodChar production.charAti;
if prodChar
stack.pushprodChar;
else
return false;
else
return false;
System.out.printlnStack: stack;
return stack.size && stack.peek$;
Given the following CFG and the parsing table, write a program to trace input strings
over the alphabet and ending with $
Given the CFG and the Predictive Parsing table below:
poinls Write a program to trace an input string given by the user, Save it as
Prog and upload it in canvas either the zip file or GitHub link Test your
programwith the following input strings:
$
$
points Show the content of the stack implementationstack flow after cach match.
points Report file Your report file should contain explanation of your code, inbuilt
functions used, important checkpoints if it is present explanation should be short and
crisp, output screenshot of your code and should not exceed more than pages.
Following is the grammar, and parsing table.
Predietive parsing table
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
