Skip to content

Instantly share code, notes, and snippets.

View V0idk's full-sized avatar

V0idk

View GitHub Profile
@V0idk
V0idk / myeval.py
Created October 26, 2021 02:04 — forked from iafisher/myeval.py
A simple implementation of a recursive-descent parser for a language of boolean expressions.
"""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)