Skip to content

Instantly share code, notes, and snippets.

View mdenson-dayspring's full-sized avatar

Matthew Denson mdenson-dayspring

View GitHub Profile
@ascv
ascv / calc.py
Last active April 23, 2025 22:14
A simple python calculator to demo recursive descent parsing. Execute the script to use the calculator. It accepts only well formed input. Use parentheses to specify operator precedence.
"""
exp ::= exp + term | exp - term | term
term ::= term * factor | term / factor | factor
factor ::= number | ( exp )
"""
class Calculator():
def __init__(self, tokens):
self._tokens = tokens
self._current = tokens[0]