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

16.12. A Sling Parser

You can create a Sling parser almost directly from the Sling grammar. You must supplement the parser with the assemblers, as Section 16.11 shows. You also must add logic for reserved words.

16.12.1. Reserved Words

In Sling, you want to allow variable definition, but you do not want to allow confusion about whether pi, s1, and s2, for example, are variables or built-in expressions. You do not want to allow

s1 = 42; // wrong 

In fact, entering this line as a program in the Sling development environment will elicit this message:

> s1 is a reserved word 

The strategy that SlingParser uses to reserve words is to modify the standard tokenizer to return specified words as a different type of token. The parser uses the class ...

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