Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created June 27, 2012 13:30
Show Gist options
  • Save fjolnir/3004079 to your computer and use it in GitHub Desktop.
Save fjolnir/3004079 to your computer and use it in GitHub Desktop.
Sum = a:Product { PushStack(a); }
( - "+" - b:Product { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorAdd left:StackTop right:b]); }
| - "-" - b:Product { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorSubtract left:StackTop right:b]); }
)* { $$ = PopStack(); }
Product = a:Variable { PushStack(a); }
( - "*" - b:Product { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorMultiply left:StackTop right:b]); }
| - "/" - b:Product { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorDivide left:StackTop right:b]); }
)* { $$ = PopStack(); }
Equation = a:Sum { PushStack(a); }
( - "<" - b:Equation { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorLesser left:StackTop right:b]); }
| - ">" - b:Equation { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorGreater left:StackTop right:b]); }
| - "<=" - b:Equation { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorLesserOrEqual left:StackTop right:b]); }
| - "=>" - b:Equation { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorGreaterOrEqual left:StackTop right:b]); }
| - "==" - b:Equation { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorEqual left:StackTop right:b]); }
| - "!=" - b:Equation { ReplaceStackTop([TQNodeOperator nodeWithType:kTQOperatorInequal left:StackTop right:b]); }
)* { $$ = PopStack(); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment