16.10 A Sling Grammar


 
Building Parsers with Java
By Steven  John  Metsker

Table of Contents
Chapter  16.   Parsing an Imperative Language

    Content

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)*; timesElement     = '*' element; divideElement    = '/' element; remainderElement = '%' element; element          = '(' expression ')'  baseElement                     negative; negative         = '-' baseElement; 

The base elements of Sling are those in Figure 16.12 plus numbers and variables :

 baseElement = Num  "pi"  "s1"  "s2"  variable       noArgs("random")          noArgs("t")               oneArg("abs")             oneArg("ceil")            oneArg("cos")             oneArg("floor")           oneArg("sin")             oneArg("tan")             twoArgs("polar")          twoArgs("cartesian")      twoArgs("scale")          twoArgs("sling"); noArgs(i)  = i; oneArg(i)  = i '(' expression ')'; twoArgs(i) = i '(' expression ',' expression ')'; 

   
Top


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

Similar book on Amazon

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