Building Parsers with Java

sjm.examples.midimath
Class MidiParser

java.lang.Object
  |
  +--sjm.examples.midimath.MidiParser

public class MidiParser
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, and avoids looping while building the subparsers.


Field Summary
protected static Sequence expression
           
 
Constructor Summary
MidiParser()
           
 
Method Summary
 Parser expression()
          Returns a parser that will recognize a Midimath expression.
static void main(java.lang.String[] args)
          Demonstrate that this utility class does not loop.
protected  Parser minusTerm()
           
protected  Parser term()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expression

protected static Sequence expression
Constructor Detail

MidiParser

public MidiParser()
Method Detail

expression

public Parser expression()
Returns a parser that will recognize a Midimath expression.
Returns:
a parser that will recognize a Midimath expression

main

public static void main(java.lang.String[] args)
Demonstrate that this utility class does not loop.

minusTerm

protected Parser minusTerm()

term

protected Parser term()

by Steve Metsker