#C371. Boolean Expression Evaluator
Boolean Expression Evaluator
Boolean Expression Evaluator
You are given a boolean expression as a string. The expression consists of the literals True
and False
, the binary operators and
and or
, and parentheses (
and )
. Your task is to evaluate the expression and output the result (True
or False
).
The grammar for the expression is defined as follows:
\( \text{expression} = \text{term} \; (\; or \; \text{term}\; )^* \)
\( \text{term} = \text{factor} \; (\; and \; \text{factor}\; )^* \)
\( \text{factor} = True \; | \; False \; | \; (\; \text{expression}\; ) \)
You can assume that the given expression is always valid.
inputFormat
The input consists of a single line containing the boolean expression to evaluate. The expression may contain spaces.
Example: True and (False or True)
outputFormat
Output a single line: True
or False
representing the result of evaluating the boolean expression.
True and (False or True)
True