O'Reilly logo

Building Parsers with Java™ by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.9. Parser Matching Utilities

Figure 10.1 shows two methods that support matching: bestMatch() and completeMatch(). The bestMatch() method accepts a single assembly, puts it in a vector, and matches against the vector. Then bestMatch() returns one assembly from the output vector of assemblies, choosing the one whose index is advanced furthest. If a grammar matches only part of an input, bestMatch() returns an assembly that shows the progress made. For example, consider matching the grammar

adjectives = ("steaming" | "hot")*; 

against the string

"hot hot steaming hot coffee" 

The following code sends bestMatch() to a parser for adjectives, showing that the parser can match up to the word "coffee":

 package sjm.examples.mechanics; import sjm.parse.*; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required