Skip to content
Mathias edited this page Sep 14, 2010 · 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+
Parents ← ‘(’ 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.
catch(err) {}

Clone this wiki locally