More tests passing.

pull/15/head
Jussi Pakkanen 11 years ago
parent 06417090a2
commit 967f0110a5
  1. 13
      interpreter.py
  2. 9
      parsertest.py

@ -1295,8 +1295,7 @@ class Interpreter():
def evaluate_if(self, node):
result = self.evaluate_statement(node.clause)
cond = None
if isinstance(result, nodes.BoolExpression) or \
isinstance(result, nodes.BoolStatement):
if isinstance(result, mparser2.BooleanNode):
cond = result.get_value()
if isinstance(result, bool):
cond = result
@ -1340,14 +1339,14 @@ class Interpreter():
def evaluate_andstatement(self, cur):
l = self.evaluate_statement(cur.left)
if isinstance(l, nodes.BoolStatement):
if isinstance(l, mparser2.BooleanNode):
l = l.get_value()
if not isinstance(l, bool):
raise InterpreterException('First argument to "and" is not a boolean.')
if not l:
return False
r = self.evaluate_statement(cur.right)
if isinstance(r, nodes.BoolStatement):
if isinstance(r, mparser2.BooleanNode):
r = r.get_value()
if not isinstance(r, bool):
raise InterpreterException('Second argument to "and" is not a boolean.')
@ -1355,14 +1354,14 @@ class Interpreter():
def evaluate_orstatement(self, cur):
l = self.evaluate_statement(cur.left)
if isinstance(l, nodes.BoolStatement):
if isinstance(l, mparser2.BooleanNode):
l = l.get_value()
if not isinstance(l, bool):
raise InterpreterException('First argument to "or" is not a boolean.')
if l:
return True
r = self.evaluate_statement(cur.right)
if isinstance(r, nodes.BoolStatement):
if isinstance(r, mparser2.BooleanNode):
r = r.get_value()
if not isinstance(r, bool):
raise InterpreterException('Second argument to "or" is not a boolean.')
@ -1370,7 +1369,7 @@ class Interpreter():
def evaluate_notstatement(self, cur):
v = self.evaluate_statement(cur.val)
if isinstance(v, nodes.BoolStatement):
if isinstance(v, mparser2.BooleanNode):
v = v.get_value()
if not isinstance(v, bool):
raise InterpreterException('Argument to "not" is not a boolean.')

@ -116,10 +116,11 @@ class Lexer:
raise ParseException('lexer', lineno, col)
class BooleanNode:
def __init__(self, token):
def __init__(self, token, value):
self.lineno = token.lineno
self.colno = token.colno
self.value = bool(token.value)
self.value = value
assert(isinstance(self.value, bool))
class IdNode:
def __init__(self, token):
@ -372,9 +373,9 @@ class Parser:
def e8(self):
t = self.current
if self.accept('true'):
return BooleanNode(t);
return BooleanNode(t, True);
if self.accept('false'):
BooleanNode(t)
BooleanNode(t, False)
if self.accept('id'):
return IdNode(t)
if self.accept('number'):

Loading…
Cancel
Save