Skip to content

Instantly share code, notes, and snippets.

@tylerhcarter
Created May 17, 2011 23:30
Show Gist options
  • Save tylerhcarter/977659 to your computer and use it in GitHub Desktop.
Save tylerhcarter/977659 to your computer and use it in GitHub Desktop.
Basic Expression Workflow
// 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