The input line: 42 The tokens are < 42 > The parseTree is [{ 42.0, [], [], 0.0 }] The value is { 42.0, [], [], 0.0 } The input line: 42~10 The tokens are < 42, ~, 10 > The parseTree is [{ 42.0, [], [], 10.0 }] The value is { 42.0, [], [], 10.0 } The input line: 42 m The tokens are < 42, m > The parseTree is [{ 42.0, [m], [], 0.0 }] The value is { 42.0, [m], [], 0.0 } The input line: 42~10 v s m The tokens are < 42, ~, 10, v, s, m > The parseTree is [{ 42.0, [m, s, v], [], 10.0 }] The value is { 42.0, [m, s, v], [], 10.0 } The input line: 5+6 The tokens are < 5, +, 6 > The parseTree is [+, [{ 5.0, [], [], 0.0 }], [{ 6.0, [], [], 0.0 }]] The value is { 11.0, [], [], 0.0 } The input line: 5-6+7 // this grammar is _right_-associative The tokens are < 5, -, 6, +, 7 > The parseTree is [-, [{ 5.0, [], [], 0.0 }], [+, [{ 6.0, [], [], 0.0 }], [{ 7.0, [], [], 0.0 }]]] The value is { -8.0, [], [], 0.0 } The input line: 5*6 The tokens are < 5, *, 6 > The parseTree is [*, [{ 5.0, [], [], 0.0 }], [{ 6.0, [], [], 0.0 }]] The value is { 30.0, [], [], 0.0 } The input line: 5/6 The tokens are < 5, /, 6 > The parseTree is [/, [{ 5.0, [], [], 0.0 }], [{ 6.0, [], [], 0.0 }]] The value is { 0.833333, [], [], 0.0 } The input line: 3 m/s The tokens are < 3, m, /, s > The parseTree is [/, [{ 3.0, [m], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]] The value is { 3.0, [m], [s], 0.0 } The input line: 3 m * 2 m/s The tokens are < 3, m, *, 2, m, /, s > The parseTree is [*, [{ 3.0, [m], [], 0.0 }], [/, [{ 2.0, [m], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]]] The value is { 6.0, [m, m], [s], 0.0 } The input line: 5+6*7 The tokens are < 5, +, 6, *, 7 > The parseTree is [+, [{ 5.0, [], [], 0.0 }], [*, [{ 6.0, [], [], 0.0 }], [{ 7.0, [], [], 0.0 }]]] The value is { 47.0, [], [], 0.0 } The input line: 18 m/s + 42 m/s The tokens are < 18, m, /, s, +, 42, m, /, s > The parseTree is [+, [/, [{ 18.0, [m], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]], [/, [{ 42.0, [m], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]]] The value is { 60.0, [m], [s], 0.0 } The input line: 5*6+7 The tokens are < 5, *, 6, +, 7 > The parseTree is [+, [*, [{ 5.0, [], [], 0.0 }], [{ 6.0, [], [], 0.0 }]], [{ 7.0, [], [], 0.0 }]] The value is { 37.0, [], [], 0.0 } The input line: 3^2 The tokens are < 3, ^, 2 > The parseTree is [^, [{ 3.0, [], [], 0.0 }], 2] The value is { 9.0, [], [], 0.0 } The input line: 3 m/s^2 The tokens are < 3, m, /, s, ^, 2 > The parseTree is [/, [{ 3.0, [m], [], 0.0 }], [^, [{ 1.0, [s], [], 0.0 }], 2]] The value is { 3.0, [m], [s, s], 0.0 } The input line: (42) The tokens are < (, 42, ) > The parseTree is [{ 42.0, [], [], 0.0 }] The value is { 42.0, [], [], 0.0 } The input line: (4+2) The tokens are < (, 4, +, 2, ) > The parseTree is [+, [{ 4.0, [], [], 0.0 }], [{ 2.0, [], [], 0.0 }]] The value is { 6.0, [], [], 0.0 } The input line: (4+2)*7 The tokens are < (, 4, +, 2, ), *, 7 > The parseTree is [*, [+, [{ 4.0, [], [], 0.0 }], [{ 2.0, [], [], 0.0 }]], [{ 7.0, [], [], 0.0 }]] The value is { 42.0, [], [], 0.0 } The input line: (3 m/s)^2 The tokens are < (, 3, m, /, s, ), ^, 2 > The parseTree is [^, [/, [{ 3.0, [m], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]], 2] The value is { 9.0, [m, m], [s, s], 0.0 } The input line: (1 m/s + 5 m/s)/(3/s) The tokens are < (, 1, m, /, s, +, 5, m, /, s, ), /, (, 3, /, s, ) > The parseTree is [/, [+, [/, [{ 1.0, [m], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]], [/, [{ 5.0, [m], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]]], [/, [{ 3.0, [], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]]] The value is { 2.0, [m], [], 0.0 } The input line: (-42) The tokens are < (, -, 42, ) > The parseTree is [-, [{ 42.0, [], [], 0.0 }]] The value is { -42.0, [], [], 0.0 } The input line: 60 m +(-18 m) The tokens are < 60, m, +, (, -, 18, m, ) > The parseTree is [+, [{ 60.0, [m], [], 0.0 }], [-, [{ 18.0, [m], [], 0.0 }]]] The value is { 42.0, [m], [], 0.0 } // testing the addition of elements to the environment, this.env // // now with PRINT_ENV set to true... The input line: def answer 42 The tokens are < def, answer, 42 > The parseTree is [def, answer, [{ 42.0, [], [], 0.0 }]] The value is { 42.0, [], [], 0.0 } The current env is [ [answer, { 42.0, [], [], 0.0 }] ] The input line: 10 answer / s The tokens are < 10, answer, /, s > The parseTree is [/, [{ 10.0, [answer], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]] The value is { 10.0, [answer], [s], 0.0 } The current env is [ [answer, { 42.0, [], [], 0.0 }] ] The input line: # 10 answer/s The tokens are < #, 10, answer, /, s > The parseTree is [#, [/, [{ 10.0, [answer], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]]] The value is { 420.0, [], [s], 0.0 } The current env is [ [answer, { 42.0, [], [], 0.0 }] ] The input line: 10 answer - 9 answer The tokens are < 10, answer, -, 9, answer > The parseTree is [-, [{ 10.0, [answer], [], 0.0 }], [{ 9.0, [answer], [], 0.0 }]] The value is { 42.0, [], [], 0.0 } The current env is [ [answer, { 42.0, [], [], 0.0 }] ] The input line: def x 3 m/s The tokens are < def, x, 3, m, /, s > The parseTree is [def, x, [/, [{ 3.0, [m], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]]] The value is { 3.0, [m], [s], 0.0 } The current env is [ [x, { 3.0, [m], [s], 0.0 }] [answer, { 42.0, [], [], 0.0 }] ] The input line: 3*(11 m/s + x) The tokens are < 3, *, (, 11, m, /, s, +, x, ) > The parseTree is [*, [{ 3.0, [], [], 0.0 }], [+, [/, [{ 11.0, [m], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]], [{ 1.0, [x], [], 0.0 }]]] The value is { 42.0, [m], [s], 0.0 } The current env is [ [x, { 3.0, [m], [s], 0.0 }] [answer, { 42.0, [], [], 0.0 }] ] The input line: def answer 7*(x+x) The tokens are < def, answer, 7, *, (, x, +, x, ) > The parseTree is [def, answer, [*, [{ 7.0, [], [], 0.0 }], [+, [{ 1.0, [x], [], 0.0 }], [{ 1.0, [x], [], 0.0 }]]]] The value is { 42.0, [m], [s], 0.0 } The current env is [ [answer, { 42.0, [m], [s], 0.0 }] [x, { 3.0, [m], [s], 0.0 }] [answer, { 42.0, [], [], 0.0 }] ] The input line: def hz 1/s The tokens are < def, hz, 1, /, s > The parseTree is [def, hz, [/, [{ 1.0, [], [], 0.0 }], [{ 1.0, [s], [], 0.0 }]]] The value is { 1.0, [], [s], 0.0 } The current env is [ [hz, { 1.0, [], [s], 0.0 }] [answer, { 42.0, [m], [s], 0.0 }] [x, { 3.0, [m], [s], 0.0 }] [answer, { 42.0, [], [], 0.0 }] ] The input line: answer + 18 m hz The tokens are < answer, +, 18, m, hz > The parseTree is [+, [{ 1.0, [answer], [], 0.0 }], [{ 18.0, [hz, m], [], 0.0 }]] The value is { 60.0, [m], [s], 0.0 } The current env is [ [hz, { 1.0, [], [s], 0.0 }] [answer, { 42.0, [m], [s], 0.0 }] [x, { 3.0, [m], [s], 0.0 }] [answer, { 42.0, [], [], 0.0 }] ]