aboutsummaryrefslogtreecommitdiffstats
path: root/sexpr.py
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2012-12-24 15:39:35 +0100
committerbnewbold <bnewbold@robocracy.org>2012-12-24 15:39:35 +0100
commit2403b07ec0a7586108798271fa04eb034445f51d (patch)
tree805f1ac5b46b484799c7c585f46b626da890dd96 /sexpr.py
parent4818443a6a7abb9fe3976dd5846d42816e9d2328 (diff)
downloadbytetunes-2403b07ec0a7586108798271fa04eb034445f51d.tar.gz
bytetunes-2403b07ec0a7586108798271fa04eb034445f51d.zip
updates to documentation, code cleanup, comments
Diffstat (limited to 'sexpr.py')
-rwxr-xr-xsexpr.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/sexpr.py b/sexpr.py
index baea66e..d508fe0 100755
--- a/sexpr.py
+++ b/sexpr.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
"""
-This code is intentionally very c-style
+This code is intentionally very c-style; it was written to make later
+development of microcontroller code faster.
"""
import sys
@@ -91,9 +92,11 @@ def strmachine(sexpr):
oper = '<'
if sexpr['cval'] == 'r':
oper = '>'
- return "(%s%s %s %s)" % (oper, oper, strmachine(sexpr['lval']), strmachine(sexpr['rval']))
+ return "(%s%s %s %s)" % (oper, oper, strmachine(sexpr['lval']),
+ strmachine(sexpr['rval']))
elif sexpr['cval'] in '+-*/^|&':
- return "(%s %s %s)" % (sexpr['cval'], strmachine(sexpr['lval']), strmachine(sexpr['rval']))
+ return "(%s %s %s)" % (sexpr['cval'], strmachine(sexpr['lval']),
+ strmachine(sexpr['rval']))
raise Exception("unexpected binary: %s" % sexpr['cval'])
def execute(sexpr, t):
@@ -146,7 +149,8 @@ def test_parse():
DEFAULT,
]
for t in tlist:
- assert strmachine(ezparse(t)) == t, "\n%s <- GOT\n%s <- EXPECTED" % (strmachine(ezparse(t)), t)
+ assert strmachine(ezparse(t)) == t, \
+ "\n%s <- GOT\n%s <- EXPECTED" % (strmachine(ezparse(t)), t)
flist = [
'',
'~',
@@ -157,7 +161,8 @@ def test_parse():
]
for f in flist:
try:
- assert strmachine(ezparse(t)) == "SHOULDFAIL", "%s <- SHOULD HAVE FAILED"% t
+ assert strmachine(ezparse(t)) == "SHOULDFAIL", \
+ "%s <- SHOULD HAVE FAILED"% t
except:
pass
print "passed all parse tests!"
@@ -184,3 +189,4 @@ def main():
if __name__=='__main__':
main()
+