From 2403b07ec0a7586108798271fa04eb034445f51d Mon Sep 17 00:00:00 2001 From: bnewbold Date: Mon, 24 Dec 2012 15:39:35 +0100 Subject: updates to documentation, code cleanup, comments --- sexpr.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'sexpr.py') 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() + -- cgit v1.2.3