Programming Problem #12
"Postfix Expressions"

Most of us are used to writing expressions in infix notation, e.g., the sum of X and Y is written "X+Y", with the operator "+" written between the operands X and Y. Another (somewhat) popular notation is postfix, in which the operator is written after the operands, e.g., "XY+". As a more significant example, the expression "(A*(B-C))/(X+Y*Z)" is written "ABC-*XYZ*+/". Postfix expressions are useful because parentheses are never required and they are easy to evaluate using a computer. Your task is to demonstrate the latter point by writing a program to evaluate postfix expressions with operator definitions.

The input will consist of one or more lines, each of which begins with the letter D or E. Lines beginning with D are definitions of the form Dx"...", where x is the operator to be defined and ... is its definition. The operator x cannot be a control character, a double quote, a digit, a space, or a predefined operator, but otherwise it may be any single character.

A line beginning with E is an evaluation and is of the form E"...", where ... is a valid postfix expression consisting of nonnegative integers, predefined operators and defined operators. Spaces may be used to separate adjacent numbers but are otherwise ignored. The predefined operators are - (subtraction), / (division), ! (duplicate) and % (swap). All operations are performed using floating-point arithmetic, and division by zero is arbitrarily defined to yield zero. For each E line in the input, display the result with exactly three digits to the right of the decimal point.

Input must be read from the file "prob12.in", and output must be written to the file "prob12.out". All output to the screen will be ignored.


Example Input

<BOF>
D+" 0%--"
E"1 2+"
D*" 1%//"
E"3 4*"
D@"!!**"
E"17 4@+6*5/"
<EOF>

Example Output

3.000
12.000
97.200

Dr. Eric Shade