Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Xorcerer committed Nov 26, 2012
1 parent 63247e9 commit 5e3ed05
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ variables.

ActionScript 3:

var expectedResult:Number = a + 2 - (+3 * (+b - -c) * 2 * (Math.max(2, 1))) - Math.min(1, d_e)
var exp:String = 'a + 2 - (+3 * (+b - -c) * 2 * ( max(2, 1))) - min(1, d_e)'

var tree:ASTree = ASTreeParser.parse(exp)
tree.setVariable('a', a)
tree.setVariable('b', b)
tree.setVariable('c', c)
tree.setVariable('d_e', d_e)
tree.setFunction('min', Math.min) // min() is built-in
actually, as well as max().
var actualResult:Number = tree.calculate()

trace(tree.toStringWithVariablesReplaced(), '=', actualResult)
Utils.assert(expectedResult == actualResult)
var expectedResult:Number = a + 2 - (+3 * (+b - -c) * 2 * (Math.max(2, 1))) - Math.min(1, d_e)
var exp:String = 'a + 2 - (+3 * (+b - -c) * 2 * ( max(2, 1))) - min(1, d_e)'

// Step 1: Parse expression string.
var tree:ASTree = ASTreeParser.parse(exp)

// Step 2: Set variables and functions
tree.setVariable('a', a)
tree.setVariable('b', b)
tree.setVariable('c', c)
tree.setVariable('d_e', d_e)
tree.setFunction('min', Math.min) // min() is built-in actually, as well as max().

// Step 3: Get the result. Step 2, 3 could be done repeatly.
var actualResult:Number = tree.calculate()

trace(tree.toStringWithVariablesReplaced(), '=', actualResult)
Utils.assert(expectedResult == actualResult)


### Supported languages:
Expand Down

0 comments on commit 5e3ed05

Please sign in to comment.