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:
Post a Comment