Changed 'assoc' to 'prec', because it's precedence.

parent a34e4894
......@@ -36,7 +36,8 @@ def generate_line(root):
('*', '/', 'mod'),
('^', )
]
max_assoc = len(operators)
max_pred = len(operators)
def is_operator(node):
"""
......@@ -47,9 +48,9 @@ def generate_line(root):
return reduce(either, map(lambda x: label in x, operators))
def assoc(node):
def pred(node):
"""
Get the associativity of an operator node.
Get the precedence of an operator node.
"""
# Check binary and n-ary operators
if not isinstance(node, Leaf) and len(node) > 1:
......@@ -60,7 +61,7 @@ def generate_line(root):
return i
# Unary operator and leaves have highest precedence
return max_assoc
return max_pred
def traverse(node):
"""
......@@ -84,7 +85,7 @@ def generate_line(root):
s += traverse(node[0])
else:
# N-ary operator
node_assoc = assoc(node)
node_pred = pred(node)
e = []
for child in node:
......@@ -92,7 +93,7 @@ def generate_line(root):
# Check if there is an precedence conflict.
# If so, add parentheses
if assoc(child) < node_assoc:
if pred(child) < node_pred:
exp = '(' + exp + ')'
e.append(exp)
......
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