A framework to separate resolution of operator precedence and associativity from parsing time
Project description
Remu-Operator
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( cons, [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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Built Distribution
Close
Hashes for remu_operator-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d72cde42d6c585d27f91ffe7adf1faa6106cbfdc2b5c99584916b71d8163b3c |
|
MD5 | 5c40b60e2a10c8570fb14f02c3251449 |
|
BLAKE2-256 | 0fb22873bc0915e0c33089f33c2da9e6e6cfdc4f84c878548e6df451241b8fde |