Generic Interpreter 0.9
Public API

gi
Class Grammar

java.lang.Object
  |
  +--gi.Lexicon
        |
        +--gi.Grammar
Direct Known Subclasses:
LL1_Grammar, LR0_Grammar

public class Grammar
extends Lexicon

This class implements a Grammar.

Version:
0.9
Author:
© 1999-2000 Craig A. Rich <carich@acm.org>
See Also:
Source code

Method Summary
 Object grab(BufferedReader source)
          Grabs terminals from a source character stream using this Grammar.
 gi.Grammar.ParseTree interpret()
          Interprets the standard input stream using this Grammar.
 gi.Grammar.ParseTree interpret(File source)
          Interprets a source file using this Grammar.
 gi.Grammar.ParseTree interpret(InputStream source)
          Interprets a source byte stream using this Grammar.
 gi.Grammar.ParseTree interpret(PipedWriter source)
          Interprets a source pipe using this Grammar.
 gi.Grammar.ParseTree interpret(Reader source)
          Interprets a source character stream using this Grammar.
 gi.Grammar.ParseTree interpret(String source)
          Interprets a source string using this Grammar.
 gi.Grammar.ParseTree interpret(String[] argv)
          Interprets by command-line arguments using this Grammar.
 
Methods inherited from class gi.Lexicon
word
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

grab

public Object grab(BufferedReader source)
            throws gi.Lexicon.Exception

Grabs terminals from a source character stream using this Grammar. Invokes Lexicon.grab(source) until it returns a terminal occurring in a phrase of this Grammar or end of source. Blocks until a character is available, an I/O error occurs, or the end of the source stream is reached.

Overrides:
grab in class Lexicon
Parameters:
source - the source character stream.
Returns:
the first terminal occurring in a phrase of this Grammar.
Throws:
gi.Lexicon.Exception - if an I/O or lexical error occurs.

interpret

public gi.Grammar.ParseTree interpret()
                               throws gi.Lexicon.Exception

Interprets the standard input stream using this Grammar.

Returns:
the ParseTree constructed by interpreting the standard input stream.
Throws:
gi.Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.

interpret

public gi.Grammar.ParseTree interpret(File source)
                               throws FileNotFoundException,
                                      gi.Lexicon.Exception

Interprets a source file using this Grammar.

Parameters:
source - the source file.
Returns:
the ParseTree constructed by interpreting source.
Throws:
FileNotFoundException - if the source file cannot be found.
gi.Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.

interpret

public gi.Grammar.ParseTree interpret(InputStream source)
                               throws gi.Lexicon.Exception

Interprets a source byte stream using this Grammar.

Parameters:
source - the source byte stream.
Returns:
the ParseTree constructed by interpreting source.
Throws:
gi.Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.

interpret

public gi.Grammar.ParseTree interpret(PipedWriter source)
                               throws IOException,
                                      gi.Lexicon.Exception

Interprets a source pipe using this Grammar.

Parameters:
source - the source pipe.
Returns:
the ParseTree constructed by interpreting source.
Throws:
IOException - if the source pipe cannot be connected.
gi.Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.

interpret

public gi.Grammar.ParseTree interpret(Reader source)
                               throws gi.Lexicon.Exception

Interprets a source character stream using this Grammar.

Parameters:
source - the source character stream.
Returns:
the ParseTree constructed by interpreting source.
Throws:
gi.Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.

interpret

public gi.Grammar.ParseTree interpret(String source)
                               throws gi.Lexicon.Exception

Interprets a source string using this Grammar.

Parameters:
source - the source string.
Returns:
the ParseTree constructed by interpreting source.
Throws:
gi.Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.

interpret

public gi.Grammar.ParseTree interpret(String[] argv)

Interprets by command-line arguments using this Grammar. When interpreting, the parser used will be (in order):

  • The parser most recently constructed by preceding command-line arguments.
  • The parser originally around this Grammar.
  • An LR(1) parser.
The first I/O, lexical, syntax or semantic error that occurs when interpreting is printed to the standard error stream. If requested, each ParseTree is printed to the standard error stream after interpreting.

Parameters:
argv - the command-line arguments controlling the interpreter.
The following arguments may appear zero or more times, are processed in order, and have the following effects:
-tree
Print each ParseTree subsequently constructed by interpreting a source stream.
-ll1
Construct an LL(1) parser around this Grammar.
-lr0
Construct an LR(0) parser around this Grammar.
-slr1
Construct an SLR(1) parser around this Grammar.
-lr1
Construct an LR(1) parser around this Grammar.
-
Interpret the standard input stream using this Grammar.
filename
Interpret source file filename using this Grammar.
If no filename arguments are given, the standard input stream is interpreted.
Returns:
the last ParseTree constructed by interpreting a source stream.

 

© 1999-2000 Craig A. Rich <carich@acm.org>