1. Engineering
  2. Computer Science
  3. an expression with binaryoperators can be expressed unambiguously as a...

Question: an expression with binaryoperators can be expressed unambiguously as a...

Question details

An expression with binaryoperators can be expressed unambiguously as a fully parenthesized infix expression (FPIE), or un-parenthesized postfix expression (UPPE). A FPIE exp is either an operand, or of the form (exp, op exp2) , where exp, and exp2 are FPIEs and op is a binary operator. The same expression as UPPE is either the said operand or of the form exp, exp2 op, where exp, and exp are UPPE equivalents of exp, and exp2, respectively. Here is an illustrative example: ((a20)/((b c) (53.4 d)) a 20 b 53.4 d* / FPIE, as equivalent UPPE Another way the same expression can be expressed unambiguously is the FPIE but with all left parentheses removed, i.e., we use only right parentheses. Lets call this version as right parenthesized infix expression (RPIE). The above example expression is a 20)/b c) 53.4 d))) as equivalent RPIE. Write a Java program that takes from the standard input a valid RPIE and outputs the equivalent FPIE and UPPE Note: Conversion from a FPIE to its equivalent RPIE is trivial: simply remove all left parentheses. However, the reverse conversion is interesting and non-trivial. An input string may include blank spaces, (right) parentheses, operands, and the four arithmetic operators /. Any character other than blank spaces, operators, and (right) parentheses will be assumed as part of an operand. Operands may be any numeric constants or variable identifiers but are not syntactically checked. Not withstanding that, IllegalArgumentException may be thrown if the input does not represent a valid RPIE.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution