sjm.examples.sling
Class SlingParser
java.lang.Object
|
+--sjm.examples.sling.SlingParser
- public class SlingParser
- extends java.lang.Object
This class provides a parser for Sling, an imperative
language that plots the path of a sling stone.
The grammar this class supports is:
statements = statement statement*;
statement = assignment | forStatement | plotStatement;
assignment = variable '=' expression ';' ;
plotStatement = "plot" expression ';';
forStatement =
"for" '(' variable ',' expression ',' expression ')'
'{' statements '}';
variable = Word;
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;
baseElement =
Num | "pi" | "random" | "s1" | "s2" | "t" | variable |
oneArg("abs") | oneArg("ceil") |
oneArg("cos") | oneArg("floor") |
oneArg("sin") | oneArg("tan") |
twoArgs("polar") | twoArgs("cartesian") |
twoArgs("scale") | twoArgs("sling");
oneArg(i) = i '(' expression ')';
twoArgs(i) = i '(' expression ',' expression ')';
The following program describes about 10,000 interesting
plots:
plot sling(1, 1) + sling(s1, 100*s2);
The class SlingIde provides an interactive
development environment for Sling.
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
expression
protected Sequence expression
statement
protected Alternation statement
baseElement
protected Alternation baseElement
wors
protected WordOrReservedState wors
tokenizer
protected Tokenizer tokenizer
SlingParser
public SlingParser()
assignment
protected Parser assignment()
baseElement
protected Parser baseElement()
comma
protected static Parser comma()
divideElement
protected Track divideElement()
element
protected Parser element()
expression
protected Parser expression()
forStatement
protected Parser forStatement()
lBrace
protected static Parser lBrace()
lParen
protected static Parser lParen()
minusTerm
protected Track minusTerm()
negative
protected Parser negative()
noArgs
protected Parser noArgs(java.lang.String name,
SlingFunction f)
num
protected Parser num()
oneArg
protected Parser oneArg(java.lang.String name,
SlingFunction f)
pi
protected Parser pi()
plotStatement
protected Parser plotStatement()
plusTerm
protected Track plusTerm()
rBrace
protected static Parser rBrace()
remainderElement
protected Track remainderElement()
reserve
protected ReservedLiteral reserve(java.lang.String s)
rParen
protected static Parser rParen()
s1
protected Parser s1()
s2
protected Parser s2()
scale
protected Parser scale()
semicolon
protected static Parser semicolon()
start
public Parser start()
statement
protected Parser statement()
statements
protected Parser statements()
term
protected Parser term()
timesElement
protected Track timesElement()
tokenizer
public Tokenizer tokenizer()
- Creates a tokenizer that uses a
WordOrReservedState
instead of a normal WordState.
twoArg
protected Parser twoArg(java.lang.String name,
SlingFunction f)
variable
protected Parser variable()
wors
protected WordOrReservedState wors()