Commit e62c02fc authored by Taddeus Kroes's avatar Taddeus Kroes

Applied pep8.

parent effe7267
......@@ -3,11 +3,13 @@ import ply.yacc as yacc
from statement import Statement as S, Block
# Global statements administration
statements = []
tokens = ('NEWLINE', 'WORD', 'COMMENT', 'DIRECTIVE', 'COMMA', 'COLON')
# Tokens
def t_NEWLINE(t):
r'\n+'
......@@ -50,6 +52,7 @@ def t_WORD(t):
r'[a-zA-Z0-9$_.+()-]+'
return t
# Ignore whitespaces
t_ignore = ' \t'
......@@ -57,9 +60,11 @@ def t_error(t):
print('Illegal character "%s"' % t.value[0])
t.lexer.skip(1)
# Build the lexer
lexer = lex.lex()
# Parsing rules
start = 'input'
......@@ -102,9 +107,14 @@ def p_command(p):
def p_error(p):
print 'Syntax error at "%s" on line %d' % (p.value, lexer.lineno)
# Build YACC
yacc.yacc()
def parse_file(filename):
"""Parse a given Assembly file, return a Block with Statement objects
containing the parsed instructions."""
global statements
statements = []
......
from math import ceil
def write_statements(statements):
"""Write a list of statements to valid assembly code."""
out = ''
......@@ -39,6 +40,9 @@ def write_statements(statements):
out += newline + line
prevline = line
# Add newline at end of file
out += '\n'
return out
def write_to_file(filename, statements):
......
......@@ -48,11 +48,11 @@ class TestDataflow(unittest.TestCase):
def test_dag_unary(self):
dag = Dag(B([S('command', 'neg.d', '$rd', '$rs')]))
expect = Dag([])
expect.nodes = [DagLeaf('$rs'), DagNode('neg.d', '$rd', DagLeaf('$rs'))]
expect.nodes = [DagLeaf('$rs'), DagNode('neg.d', '$rd', \
DagLeaf('$rs'))]
self.assertEqualDag(dag, expect)
def test_dag_binary(self):
dag = Dag(B([S('command', 'addu', '$rd', '$r1', '$r2')]))
expect = Dag([])
......@@ -62,7 +62,6 @@ class TestDataflow(unittest.TestCase):
self.assertEqualDag(dag, expect)
# def test_dag_combinednode(self):
# dag = Dag(B([S('command', 'mult', '$rd1', '$r1', '$r2'),
# S('command', 'mult', '$rd2', '$r1', '$r2')]))
......@@ -77,7 +76,6 @@ class TestDataflow(unittest.TestCase):
#
# self.assertEqualDag(dag, expect)
def assertEqualDag(self, dag1, dag2):
self.assertEqual(len(dag1.nodes), len(dag2.nodes))
......@@ -91,7 +89,7 @@ class TestDataflow(unittest.TestCase):
elif isinstance(node2, DagLeaf):
raise AssertionError
else:
self.assertEqual(node1.op , node2.op)
self.assertEqual(node1.op, node2.op)
self.assertEqual(node1.labels, node2.labels)
self.assertEqual(len(node1.nodes), len(node2.nodes))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment