Comparisons work.

pull/15/head
Jussi Pakkanen 11 years ago
parent d6924da005
commit 3c591385ed
  1. 10
      interpreter.py
  2. 16
      parsertest.py

@ -725,7 +725,7 @@ class Interpreter():
return self.evaluate_if(cur)
elif isinstance(cur, mparser2.IdNode):
return self.get_variable(cur.value)
elif isinstance(cur, mparser2.EqualNode): # FIXME, should be comparison
elif isinstance(cur, mparser2.ComparisonNode):
return self.evaluate_comparison(cur)
elif isinstance(cur, mparser2.ArrayNode):
return self.evaluate_arraystatement(cur)
@ -1310,8 +1310,8 @@ class Interpreter():
return False
def evaluate_comparison(self, node):
v1 = self.evaluate_statement(node.get_first())
v2 = self.evaluate_statement(node.get_second())
v1 = self.evaluate_statement(node.left)
v2 = self.evaluate_statement(node.right)
if self.is_elementary_type(v1):
val1 = v1
else:
@ -1323,9 +1323,9 @@ class Interpreter():
if type(val1) != type(val2):
raise InterpreterException('Comparison of different types %s and %s.' %
(str(type(val1)), str(type(val2))))
if node.get_ctype() == '==':
if node.ctype == '==':
return val1 == val2
elif node.get_ctype() == '!=':
elif node.ctype == '!=':
return val1 != val2
else:
raise InvalidCode('You broke me.')

@ -169,19 +169,13 @@ class AndNode:
self.left = left
self.right = right
class EqualNode:
def __init__(self, lineno, colno, left, right):
self.lineno = lineno
self.colno = colno
self.left = left
self.right = right
class NEqualNode:
def __init__(self, lineno, colno, left, right):
class ComparisonNode:
def __init__(self, lineno, colno, ctype, left, right):
self.lineno = lineno
self.colno = colno
self.left = left
self.right = right
self.ctype = ctype
class NotNode:
def __init__(self, lineno, colno, value):
@ -337,9 +331,9 @@ class Parser:
def e4(self):
left = self.e5()
if self.accept('equal'):
return EqualNode(left.lineno, left.colno, left, self.e5())
return ComparisonNode(left.lineno, left.colno, '==', left, self.e5())
if self.accept('nequal'):
return NEqualNode(left.lineno, left.colno, left, self.e5())
return ComparisonNode(left.lineno, left.colno, '!=', left, self.e5())
return left
def e5(self):

Loading…
Cancel
Save