Created
May 17, 2011 23:30
-
-
Save tylerhcarter/977659 to your computer and use it in GitHub Desktop.
Basic Expression Workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the value before the operator | |
if((i - 1) < 0){ | |
throw new SyntaxException ("Badly Formed Expression.", tokens); | |
} | |
Value numerator = this.engine.evaluate(tokens.get(i - 1), scope); | |
// Get the value after the operator | |
if((i + 1) >= tokens.size()){ | |
throw new SyntaxException ("Badly Formed Expression.", tokens); | |
} | |
Value divisor = this.engine.evaluate(tokens.get(i + 1), scope); | |
Expression expression = new Expression(numerator, divisor); | |
// Preform the operation | |
Token newToken = evaluateExpression(expression, scope); | |
// Replace Left Value, Operator, and Right Value with the new Value | |
slice(tokens, i-1, i+1); | |
tokens.add(i - 1, newToken); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment