Module 05: The Arith language: pretty-printing

Arith syntax and semantics

The Arith language is represented by the following abstract syntax:

(We are using the name Arith1 to avoid a name clash, since later we will use a more refined version called Arith.) The semantics of an Arith expression is an integer: Lit1 values represent themselves, Add represents addition, Sub subtraction, and Mul multiplication. For example, arithExample evaluates to \((4 \times 5) + 2 = 22\), and arithExample2 evaluates to \(4 \times (5 + 2) = 28\).

As concrete syntax for Arith, we use standard mathematical notation and standard conventions about operator precedence. For example, "4*5+2" is concrete syntax for arithExample, since by convention multiplication has higher precedence than addition. If we want concrete syntax to represent arithExample2, we have to use parentheses: "4*(5+2)".

Class discussion: precedence

A better pretty-printer