Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Specification Design, write and test a program that accepts an arithmetic expression of unsigned integers in postfix notation in which the tokens are separated

1. Specification Design, write and test a program that accepts an arithmetic expression of unsigned integers in postfix notation in which the tokens are separated by spaces and builds and processes the arithmetic expression tree that represents that expression. The main class will be P2GUI. It should create a Swing based GUI shown below: image text in transcribed

The GUI must be generated by code that you write. You may not use a drag-and-drop GUI generator. Pressing the Construct Tree button should cause the following: (i) the arithmetic expression tree that represents the entered postfix expression will be constructed, (ii) using that tree, the corresponding fully parenthesized infix expression should be generated and displayed in the GUI and finally (iii) a file should be generated that contains the 3-address format instructions corresponding to the arithmetic expression. These topics, including relevant classes for implementing and processing an expression tree, are discussed in the week 4 reading Binary Trees, Expression Trees, BST (AVL) trees, and B-Trees section II Expression Trees. The above example should produce the following output file containing the 3-address instructions: Add R0 5 9 Sub R1 3 R0 Mul R2 2 3 Div R3 R1 R2 It is not necessary to reuse registers within an expression as shown in the above mentioned reading and you can assume there are as many available registers as needed. Each new expression should, however, begin using registers starting at R0. You may assume that the expression is syntactically correct with regard to the order of operators and operands, but you should check for invalid tokens, such as characters that are not valid operators or operands such as 2a, which are not valid integers. If an invalid token is detected, a checked custom exception InvalidTokenException should be thrown and caught by the main class and an appropriate error message should be displayed in an JOptionPane. Below is an example:

image text in transcribed

Your program should compile without errors. The Google recommended Java style guide (https://google.github.io/styleguide/javaguide.html) should be used to format and document your code. Specifically, the following style guide attributes should be addressed: header comments include filename, author, date and brief purpose of the program; In-line comments used to describe major functionality of the code; the meaning and the role of variables and constants are indicated as code comments; meaningful variable names and prompts applied; class names are written in UpperCamelCase; variable names are written in lowerCamelCase; constant names are in written in All Capitals; braces use K&R style. In addition the following design constraints should be followed: declare all instance variables private; avoid the duplication of code.

Three Adddress Generator Enter Postfix Expression 359+ 23* onstruct Tree Infix Expression ((3-(5+9))/(2*3)) Three Adddress Generator Enter Postfix Expression 359+ 23* onstruct Tree Infix Expression ((3-(5+9))/(2*3))

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

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

What area of performance does the business area want us to measure?

Answered: 1 week ago