2.1. What Is a Parser?

A parser is an object that recognizes the elements of a language and translates each element into a meaningful result. A language is a set of strings, and we usually have some way of describing a language as containing all the strings that match a pattern. A fundamental ability of a parser is the ability to declare whether or not a given string belongs to a language. Consider the following language:

{"hot coffee", 
 "steaming coffee",
 "hot hot hot coffee",
 "hot hot steaming hot coffee",
 ...}

This language contains all strings that begin with some sequence of "hot" and "steaming" and end with "coffee". A parser for this language is an object that can recognize whether or not a given string is an element of this language. ...

Get Building Parsers with Java™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.