Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The parsers of the preceding examples simply computed numeric results. When you build an interpreter or compiler, you will instead want to build up a parse tree. This is usually done with case classes. For example, the following classes can represent an arithmetic expression:
class Expr case class Number(value: Int) extends Expr case class Operator(op: String, left: Expr, right: Expr) extends Expr