% $Id: ExpressionParserTest.oz,v 1.1 2007/11/26 21:17:22 leavens Exp leavens $ \insert 'ExpressionParser.oz' \insert 'SolveAll.oz' \insert 'TestingNoStop.oz' % A helper function for tests fun {Parses LoA} {SolveAll proc {$ PTree} PTree={Expression LoA nil} end} end {Test {Parses [3]} '==' [numExp(3)]} {Test {Parses [foo]} '==' [idExp(foo)]} {Test {Parses [foo '+' 3]} '==' [plusExp(idExp(foo) numExp(3))]} {Test {Parses [7 '*' foo '+' 3]} '==' [timesExp(numExp(7) plusExp(idExp(foo) numExp(3)))]} {Test {Parses ['if' 6 '>' 7 '*' foo 'then' 3 'else' bar]} '==' [ifExp(gtExp(numExp(6) timesExp(numExp(7) idExp(foo))) numExp(3) idExp(bar))]} {Test {Parses ['if' baz 'then' 4 'else' bar]} '==' [ifExp(idExp(baz) numExp(4) idExp(bar))]} {Test {Parses ['if' 6 '>' 7 '*' foo 'then' 3]} '==' [ifExp(gtExp(numExp(6) timesExp(numExp(7) idExp(foo))) numExp(3) numExp(0))]} % The classic dangling-else ambiguity {Test {Parses ['if' 6 '>' 7 '*' foo 'then' 'if' baz 'then' 4 'else' bar]} '==' [ifExp(gtExp(numExp(6) timesExp(numExp(7) idExp(foo))) ifExp(idExp(baz) numExp(4) numExp(0)) idExp(bar)) ifExp(gtExp(numExp(6) timesExp(numExp(7) idExp(foo))) ifExp(idExp(baz) numExp(4) idExp(bar)) numExp(0))]}