sjm.examples.midimath
Class Midiloop
java.lang.Object
|
+--sjm.examples.midimath.Midiloop
- public class Midiloop
- extends java.lang.Object
This class creates and uses a parser that aims
to recognize simple arithmetic expressions, but gets
caught in a loop. Allowable expressions include the
use of multiplication, addition and parentheses. The
grammar for this language is:
expression = term ('+' term)*;
term = factor ('*' factor)*;
factor = '(' expression ')' | Num;
This class implements this grammar as a utility class,
but introduces a definitional loop in so doing.
|
Method Summary |
Parser |
expression()
Returns a parser that will recognize a Midimath
expression. |
protected Parser |
factor()
Returns a parser that will recognize either
numbers, or arithmetic expressions in parentheses. |
static void |
main(java.lang.String[] args)
Demonstrate an infinite loop! |
protected Parser |
term()
Returns a parser that will recognize arithmetic
expressions containing just multiplication. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Midiloop
public Midiloop()
expression
public Parser expression()
- Returns a parser that will recognize a Midimath
expression.
- Returns:
- a parser that will recognize a Midimath
expression
factor
protected Parser factor()
- Returns a parser that will recognize either
numbers, or arithmetic expressions in parentheses.
- Returns:
- a parser that will recognize either
numbers, or arithmetic expressions in
parentheses
main
public static void main(java.lang.String[] args)
- Demonstrate an infinite loop!
term
protected Parser term()
- Returns a parser that will recognize arithmetic
expressions containing just multiplication.
- Returns:
- a parser that will recognize arithmetic
expressions containing just multiplication