#C12171. Evaluate Mathematical Expression

    ID: 41569 Type: Default 1000ms 256MiB

Evaluate Mathematical Expression

Evaluate Mathematical Expression

You are given a string representing a mathematical expression which may contain addition (+), subtraction (-), multiplication (*), division (/), and parentheses. The expression can include both integers and floating point numbers. Your task is to evaluate the expression following the standard operator precedence rules. In other words, the expression should be parsed according to the grammar:

\( E \to T \; ( ( + | - ) \; T )^* \)

\( T \to F \; ( ( * | / ) \; F )^* \)

\( F \to (E) \; | \; number \)

If the expression is invalid (for example due to a syntax error, division by zero, or the presence of invalid characters), your program should output exactly Invalid expression.

Note: All formulas are given in \( \LaTeX \) format and the output must be produced to standard output based on an input read from standard input.

inputFormat

The input consists of a single line that contains the mathematical expression to be evaluated. The expression may contain spaces and is guaranteed to have a length of at least 1 character.

outputFormat

Output a single line with the result of the evaluated expression. If the expression is valid and the result is mathematically an integer, output it as an integer; otherwise output the floating point result. In the event of any error (such as invalid syntax, division by zero, or invalid characters), output exactly Invalid expression.

## sample
2 + 3
5