Skip to content
← All demos

Expression parser

The exact pure-Swift grammar from the iOS app, ported to TypeScript. Type or click a sample to see how it parses — including the five named error cases.

Addition: 12 + 7 = 19

Grammar

  • X + Y where X, Y ∈ [0, 99]
  • X − Y where X, Y ∈ [0, 99] and X ≥ Y
  • N where N ∈ [0, 999] (renders as place-value)

Anything else — multi-term, negative result, out-of-range — fails with a named error and a friendly hint. After three misreads the iOS app suggests printing a worksheet.