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 March 17, 2022 04:06
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 ::= term | exp + term | exp - term
term ::= factor | factor * term | factor / term
factor ::= number | ( exp )
"""
class Calculator():
def __init__(self, tokens):
self._tokens = tokens
self._current = tokens[0]