Consider the following expression BNF:

::= + | - |

::= * | / |

::= | ( )

::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Using recursive descent, and only recursive descent, scan expressions that adhere to this BNF

to build their expression tree; write an integer valued function that scans the tree to

evaluate the expression represented by the tree.

There are plenty of clever programs online that you can download to evaluate arithmetic

expression tree; if you want zero in this assignment, download one and submit it as

programming assignment #2; if you want a grade greater than zero, please follow our

instructions. Thanks.

Input:

• A numeric expression adhering to this BNF.

Output:

• Some representation of the expression tree.

• The result of evaluating the expression.

Answers

Answer 1

The program will be:

import java.io.IOException;

import java.util.Scanner;

/* This class represents a Node in Expression Tree that will contain a digit(symbol) and will have links to its

* left and right childs, which would be recursively having its own left and right sub childs accordingly

*/

class Node {

public char data; // Store Node Data

public Node leftChild; // pointer to left sub tree

public Node rightChild;// pointer to right sub tree

// Constructor to initialize Node with data

public Node(char x) {

data = x;

}

// display the Node's data stored

public void displayNode() {

System.out.print(data);

}

}

/* This is Stack class (Stack1) which performs push(), pop(), isEmpty() operation on Node's data */

class Stack1 {

private Node[] a; // Stack of type Node

private int top, m; // top = top of stack variable, m = Maximum Size of the Stack

public Stack1(int max) {

m = max;

a = new Node[m];

top = -1;

}

What is a have program?

Java is a popular object-oriented programming language and software platform that powers billions of devices such as notebook computers, mobile devices, gaming consoles, medical devices, and many more.

Java's rules and syntax are based on the C and C++ programming languages. The program is illustrated based on the information.

Learn more about program on:

https://brainly.com/question/26642771

#SPJ1


Related Questions

Other Questions
Suppose that congress were to institute an investment tax credit. What would happen in the market for loanable funds?. Why people were unhappy with their government in china? recently issued bonds that mature in 17 years. they have a par value of $1,000 and an annual coupon of 11.8%. if the current market interest rate is 10%, what is the current yield of this bond? although birds and mammals descended from different ancestors, they both have a four-chambered heart. this is the result of which expression is equivanlent to -18 - 5 What sould always be included in an example of formal writing The function g(x) = x2 10x + 24 is graphed on a coordinate plane. Where will the function cross the x-axis?(6, 0) and (4, 0)(2, 0) and (12, 0)(4, 0) and (6, 0)(12, 0) and (2, 0) how would the measurements be analyzed in order to test carlo's claim about the behavior of a spriung and a rubber band what is the predetermined overhead rate, and why do companies use this calculation to apply manufacturing overhead? Mark all of the terms that are related to the structure of DNA. aribonucleic acid bguanine cdouble helix dhydrogen bonds ethymine fsingle helix gadenine hdeoxyribonucleic acid icytosine juracil three outcomes of the Boston Massacre. why are fermentation reactions important for cells? they regenerate nad so that glycolysis can continue to operate. they produce alcohol, which enhances the permeability of their mitochondrial membranes to proton translocation. they allow the cell to conserve oxygen for the citric acid cycle. they generate oxygen. Help me please image is attached I really appreciate it The scatterplot illustrates the relationship between two quantitative variables: the amount of an active ingredient in a medicine and the level of pain relief (on a scale of 1 to 10).The relationship in the scatterplot isweakpositive and linear.positive and nonlinear.negative and moderately strong. im struggling fr help me what are the core processes of business identified by bossidy and charan? (choose every correct answer.) which of the characteristics of a good critical thinkers entails acknowledging and benefiting from our interconnectedness? question 21 options: creative problem solving none of these mindfulness collaborative learning two parallel plates are maintained with constant voltage by a battery as they are pulled apart. what happens to the strength of the electric field during this process? which of the following is a linear equation it is supposed to be travel and tourismShonda is an expert on the various service cultures that exist within the hospitality industry. Specifically, Shonda works in service marketing and arranges the markets into smaller groups rather than just targeting customers individually. How does arranging markets into smaller groups benefit Shondas work? A. It instantly boosts her profits and ensures that she will get a sizeable bonus this year. B. It lets her use a wider range of marketing strategies. C. It guarantees that each of her marketing campaigns will be successful. D. It allows her to use her companys time, money, and other resources more efficiently.