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 ...

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.