Skip to content

Instantly share code, notes, and snippets.

View gardyna's full-sized avatar

Dagur Arinbjörn Daníelsson gardyna

View GitHub Profile
@gardyna
gardyna / reverse_polish_evaluator.py
Last active September 28, 2019 06:20 — forked from viebel/reverse_polish_evaluator.py
reverse polish evaluator in python
# This example assumes binary operators, but this is easy to extend.
# Comes from this excellent article: http://blog.reverberate.org/2013/07/ll-and-lr-parsing-demystified.html
ops = {
"+": (lambda a, b: a + b),
"-": (lambda a, b: a - b),
"*": (lambda a, b: a * b),
"/": (lambda a, b: a / b)
}
def eval(expression):