Skip to main content

A framework to separate resolution of operator precedence and associativity from parsing time

Project description


This is framework to separate the resolution of operator precedence and associativity from parsing time, by using a concise algorithm instead of Shunting Yard algorithm.

Taine Zhao is the author of this algorithm, and has named it "Operator Bubbling".

from remu_operator import Operator, binop_reduce

precedences = {
    '+': 1,
    '*': 2,
    "^": 3,

left = False
right = True

associativities = {'+': left, '*': left, '^': right}

def cons(v):
    return lambda l, r: '({} {} {})'.format(l, v, r)

x = binop_reduce(
    [1, Operator("+"), 2,
     Operator("*"), 3, Operator("^"), 4,
     Operator("^"), 5, Operator("+"), 6,
     Operator("*"), 7], precedences, associativities)

assert x == '((1 + (2 * (3 ^ (4 ^ 5)))) + (6 * 7))'

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for remu-operator, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size remu_operator-1.0.1-py3-none-any.whl (3.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page