Permalink
Browse files

Merge branch 'master' of github.com:kragen/pytebeat

  • Loading branch information...
2 parents 24ad41a + bc1922d commit 49bc767d8500745e6585278bbc5750ed11ff471a Default User committed Jan 19, 2013
Showing with 17 additions and 1 deletion.
  1. +17 −1 shuntparse.py
View
@@ -145,7 +145,10 @@ def eval(self, left, right):
return binary_denotations[self.text](left, right)
class BinaryMinus(BinaryOp): pass
-class Leaf(Token): pass
+class Leaf(Token):
+ def rpn(self):
+ return self.text
+
class Variable(Leaf):
def eval(self, env):
return env[self.text]
@@ -215,6 +218,13 @@ def eval(self, env):
left = self.left.eval(env)
right = self.right.eval(env)
return self.op.eval(left, right)
+ def rpn(self):
+ if self.op.text == '=':
+ return ' '.join([self.right.rpn(), 'constant', self.left.text])
+ elif self.op.text == ',':
+ return ' '.join([self.left.rpn(), '', self.right.rpn()])
+ else:
+ return ' '.join([self.left.rpn(), self.right.rpn(), self.op.text])
class UnaryApply(Apply):
def __init__(self, op, operand):
@@ -226,6 +236,11 @@ def __str__(self):
def eval(self, env):
value = self.operand.eval(env)
return self.op.eval(value)
+ def rpn(self):
+ if self.op.text == '-':
+ return ' '.join(['0', self.operand.rpn(), '-'])
+ else:
+ return ' '.join([self.operand.rpn(), self.op.text])
# Here we introduce a dependency on Numeric, and force return values
# of booleans and comparators to be (possibly zero-dimensional)
@@ -289,6 +304,7 @@ def play_bytebeat(astr, out):
return
if out is not sys.stdout:
print formula
+ print formula.rpn()
while True:
x = formula.eval({'t': arange(t, t+n_samples)})

0 comments on commit 49bc767

Please sign in to comment.