Simple Calculator

2beaucoup edited this page Sep 21, 2012 · 6 revisions

The Simple Calculator example lives in the org.parboiled.examples.calculators package and is a set of two example parsers show-casing a simple recognizer and an actual calculator built with parboiled for Scala.

The first one, the SimpleCalculator0 is a simple recognizer for the following basic grammar, without any parser actions:

Expression ← Term ((‘+’ / ‘-’) Term)*
Term ← Factor ((‘*’ / ‘/’) Factor)*
Factor ← Number / Parens
Number ← Digit+
Parens ← ‘(’ expression ‘)’
Digit ← [0-9]

The SimpleCalculator1 examples adds parser actions that perform the actual calculations directly on the parsers value stack, without first creating an AST for the expression.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.