2.1 What Is a Parser?


 
Building Parsers with Java
By Steven  John  Metsker

Table of Contents
Chapter  2.   The Elements of a Parser

    Content

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. For example, this parser will be able to determine that the following is a member of the language:

 "hot hot hot steaming hot steaming hot coffee" 

whereas the following is not:

 "lukewarm coffee" 

Every parser defines a language ”the language that is the set of all strings that the parser recognizes. Notice that such sets are usually infinite. In practice, you never create a set that contains all the members of a language. Rather, you construct parsers to match patterns of text.

To create a new language you create a new parser object, and this means that you need a Parser class. This class does not operate alone; it collaborates with two other classes.


   
Top


Building Parsers with Java
Building Parsers With Javaв„ў
ISBN: 0201719622
EAN: 2147483647
Year: 2000
Pages: 169

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net