This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A simple implementation of a recursive-descent parser for a language of boolean expressions.""" | |
import readline | |
def eval_str(expr): | |
"""Evaluate a boolean expression with the symbols '0', '1', '|', '&', '(' and ')'. All binary | |
operators must be wrapped in parentheses, even when it would be unambiguous to omit them. | |
""" | |
tokens = tokenize(expr) | |
ast = match_expr(tokens) |