Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm trying to solve this Question But I have this code import java.util.Scanner; import java.util.Stack; public class BottomUpLRParser { private static final int[][] parsingTable =

I'm trying to solve this Question image text in transcribed

But I have this code

import java.util.Scanner; import java.util.Stack; public class BottomUpLRParser { private static final int[][] parsingTable = { // i + * ( ) $ /*0*/ {1, 0, 0, 2, 0, 0}, /*1*/ {0, 3, 3, 0, 0, 4}, /*2*/ {0, 0, 0, 2, 5, 5}, /*3*/ {0, 0, 0, 0, 6, 6}, /*4*/ {0, 0, 0, 0, 0, 0}, /*5*/ {1, 0, 0, 2, 0, 0}, /*6*/ {0, 0, 0, 0, 0, 0}, }; private static final int[] reduceTable = { 0, /* reduce by production 1 */ 1, /* reduce by production 2 */ 2, /* reduce by production 3 */ 3, /* reduce by production 4 */ -1, /* accept */ }; public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the expression: "); String input = sc.nextLine(); //input = input + "$"; Stack stack = new Stack(); stack.push(0); int state, symbol; for (int i = 0; i  0) { System.out.println("Action: Shift"); stack.push(symbol); stack.push(parsingTable[state][symbol]); } else if (parsingTable[state][symbol]  

But when it runs, I keep getting the wrong output image text in transcribed

LR parsing example Enter the expression: i+ii$ Stack: [0] Input: i+ii$ Action: Shift Stack: [0,0,1] Input: +i*i\$ Action: Shift Stack: [0,0,1,1,3] Input: i*i\$ Error Not Accepted Process finished with exit code 0

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions