Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Denson mdenson-dayspring

View GitHub Profile
@ascv
ascv / calc.py
Last active Sep 30, 2021
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.
View calc.py
"""
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]