Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

Chapter 33: Combinator Parsing > 33.2 Running your parser - Pg. 730

C HAPTER 33 · Combinator Parsing operator. That way, the parser code keeps closely to the visual appear- ance of the grammar--it just replaces spaces by ~ characters. 4. Repetition is expressed rep( . . . ) instead of { . . . }. Analogously (though not shown in the example), option is expressed opt( . . . ) instead of [ . . . ]. 5. The period (.) at the end of each production is omitted--you can, how- ever, write a semicolon ( ; ) if you prefer. That's all there is to it. The resulting class Arith defines three parsers, expr , term and factor , which can be used to parse arithmetic expressions and their parts. 33.2 Running your parser You can exercise your parser with the following small program: object ParseExpr extends Arith { def main(args: Array[String]) {