16.10. A Sling Grammar

A Sling program is a series of statements:

statements = statement statement*; 

These statements may be either assignment statements, for statements, or plot statements:

statement     = assignment | forStatement | plotStatement; 
assignment    = variable '=' expression ';' ;
plotStatement = "plot" expression ';';
forStatement  =
    "for" '(' variable ',' expression ',' expression  ')'
    '{' statements '}';

A variable is any unreserved word; the reserved words in Sling are the elements shown in Figure 16.12.

variable = Word; 

Expressions in Sling allow for normal arithmetic manipulation:

 expression = term (plusTerm | minusTerm)*; plusTerm = '+' term; minusTerm = '-' term; term = element (timesElement | divideElement | remainderElement)*; ...

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.