Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
C HAPTER 33 ยท Combinator Parsing 33.8 Lexing and parsing The task of syntax analysis is often split into two phases. The lexer phase recognizes individual words in the input and classifies them into some token classes. This phase is also called lexical analysis. This is followed by a syntactical analysis phase that analyzes sequences of tokens. Syntactical analysis is also sometimes just called parsing, even though this is slightly imprecise, as lexical analysis can also be regarded as a parsing problem. The Parsers trait as described in the previous section can be used for either phase, because its input elements are of the abstract type Elem . For lexical analysis, Elem would be instantiated to Char , meaning the individual characters that make up a word are being parsed. The syntactical analyzer would in turn instantiate Elem to the type of token returned by the lexer. Scala's parsing combinators provide several utility classes for lexical and syntactic analysis. These are contained in two sub-packages, one for each kind of analysis: scala.util.parsing.combinator.lexical scala.util.parsing.combinator.syntactical