Sunday, August 15, 2010

UVa 622 Grammar Evaluation

Problem: evaluate an integer expression with +, *, and (). The grammar of evaluting parentheses first, then multiplication and finally addition is given. Strings which are not in the grammar must report an error.

Solution: recursively parse the string according to the grammar. In fact, there are 3 recursive function to parse expressions, components and factors separately in my code.

Note: the grammar states positive integers, which includes 0.

No comments: