Single Digit Adder
InterviewTime limit1sMemory limit128 MB
Evaluate each line as an arithmetic expression of single digits with plus, minus, and parentheses.
Problem
Write a program that evaluates expressions built from the following grammar, written roughly in BNF (Backus Naur Form).
expr ::= term | expr '+' term | expr '-' term
unary_op ::= '+' term | '-' term
term ::= '(' expr ')' | '(' unary_op ')' | literal
literal ::= [0-9]
An expression contains no whitespace. Every expression consists only of the characters (, ), +, - and the digits 0 through 9. You may assume that every expression in the input is well-formed.
Input
The input holds one expression per line, and each line ends with a newline. The length of an expression does not exceed 200. There are no blank lines, and the input continues to the end of the file.
Output
For each expression, print its integer value on its own line.