How to format the output the corresponding infix expression


Problem

Translates a valid prefix expression into the corresponding infix expression. With prefix notation, an operator appears at the beginning of its two operands. For the resulting infix expression, the operands will appear on each side of the operator to be applied. We shall be using constants; both positive and negative single digit whole numbers and positive and negative single digit to the right and/or left of the decimal point real numbers. Be careful here - you might want to consult the Java Language Reference Manual for allowed number formats.

One last cautionary statement - while this is an exercise in reformatting, the infix version of the original version of an expression must compute the same answer as the original version did.

How to format the output (the corresponding infix expression)? The compiler textbook allows for printing a string when a RHS of a rule is identified (see solutions to problems 1 & 2 in chapter 2 of the book). The syntax we will use will be similar to C code. We shall use a print statement where each element to be printed shall be interpreted as a string. Here is an example.

Rule: ::= = {print("+",,,"=")}

Input: 4 + 5 = Output: + 4 5 =

a) The full definition of the grammar for the prefix expression language. Note that the definition consists of 4 parts: terminals, nonterminals, grammar rules, and the start symbol and you must provide detail for each part.

b) Four non-trivial prefix expressions that are valid that are demonstratively different. In this context, non-trivial means multiple constants and operators.

c) Four non-trivial invalid prefix expressions where each expression given represents a different type of error. You are asked to include an English description of the error with the chosen expression.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: How to format the output the corresponding infix expression
Reference No:- TGS03312193

Expected delivery within 24 Hours