Can do logical or.

pull/15/head
Jussi Pakkanen 12 years ago
parent 6a5a9a3848
commit 782021d65e
  1. 17
      interpreter.py
  2. 6
      mparser.py
  3. 22
      test cases/common/40 logic ops/meson.build

@ -843,6 +843,8 @@ class Interpreter():
return cur
elif isinstance(cur, nodes.AndStatement):
return self.evaluate_andstatement(cur)
elif isinstance(cur, nodes.OrStatement):
return self.evaluate_orstatement(cur)
else:
raise InvalidCode("Unknown statement.")
@ -1247,6 +1249,21 @@ class Interpreter():
raise InterpreterException('Second argument to "and" is not a boolean.')
return r
def evaluate_orstatement(self, cur):
l = self.evaluate_statement(cur.left)
if isinstance(l, nodes.BoolStatement):
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):
r = r.get_value()
if not isinstance(r, bool):
raise InterpreterException('Second argument to "or" is not a boolean.')
return r
def evaluate_arraystatement(self, cur):
(arguments, kwargs) = self.reduce_arguments(cur.get_args())
if len(kwargs) > 0:

@ -71,7 +71,7 @@ precedence = (
('nonassoc', 'EQUALS', 'NEQUALS'),
('left', 'OR'),
('left', 'AND'),
('nonassoc', 'COLON')
('nonassoc', 'COLON'),
('left', 'DOT'),
)
@ -196,6 +196,10 @@ def p_statement_and(t):
'statement : statement AND statement'
t[0] = nodes.AndStatement(t[1], t[3])
def p_statement_or(t):
'statement : statement OR statement'
t[0] = nodes.OrStatement(t[1], t[3])
def p_empty_else(t):
'elseblock : '
return None

@ -27,13 +27,13 @@ else
error('Not ok.')
endif
if t and t
if true and t
message('Ok.')
else
error('Not ok.')
endif
if t and f
if t and false
error('Not ok.')
else
message('Ok.')
@ -44,3 +44,21 @@ if f and t
else
message('Ok.')
endif
if f or false
error('Not ok.')
else
message('Ok.')
endif
if true or f
message('Ok.')
else
error('Not ok.')
endif
if t or true
message('Ok.')
else
error('Not ok.')
endif

Loading…
Cancel
Save