net.percederberg.grammatica
Class Grammar

java.lang.Object
  |
  +--net.percederberg.grammatica.Grammar

public class Grammar
extends java.lang.Object

A grammar definition object. This object supports parsing a grammar file and create a lexical analyzer (tokenizer) for the grammar.

Version:
1.0
Author:
Per Cederberg,

Field Summary
static java.lang.String AUTHOR_DECLARATION
          The author grammar declaration constant.
static java.lang.String COPYRIGHT_DECLARATION
          The copyright grammar declaration constant.
static java.lang.String DATE_DECLARATION
          The date grammar declaration constant.
static java.lang.String DESCRIPTION_DECLARATION
          The description grammar declaration constant.
static java.lang.String GRAMMAR_TYPE_DECLARATION
          The grammar type grammar declaration constant.
static java.lang.String LICENSE_DECLARATION
          The license grammar declaration constant.
static java.lang.String VERSION_DECLARATION
          The version grammar declaration constant.
 
Constructor Summary
Grammar(java.io.File file)
          Creates a new grammar from the specified file.
 
Method Summary
 Parser createParser(Tokenizer tokenizer)
          Creates a parser from this grammar.
 Tokenizer createTokenizer(java.io.Reader in)
          Creates a tokenizer from this grammar.
 java.lang.String getDeclaration(java.lang.String name)
          Returns the declaration value for the specified name.
 java.lang.String getFileName()
          Returns the grammar file name.
 ProductionPattern getProductionPattern(int pos)
          Returns a specific production pattern.
 ProductionPattern getProductionPattern(java.lang.String name)
          Returns a specific production pattern.
 int getProductionPatternCount()
          Returns the number of production patterns in the grammar.
 TokenPattern getTokenPattern(int pos)
          Returns a specific token pattern.
 TokenPattern getTokenPattern(java.lang.String name)
          Returns a specific token pattern.
 int getTokenPatternCount()
          Returns the number of token patterns in the grammar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTHOR_DECLARATION

public static final java.lang.String AUTHOR_DECLARATION
The author grammar declaration constant.

See Also:
Constant Field Values

COPYRIGHT_DECLARATION

public static final java.lang.String COPYRIGHT_DECLARATION
The copyright grammar declaration constant.

See Also:
Constant Field Values

DATE_DECLARATION

public static final java.lang.String DATE_DECLARATION
The date grammar declaration constant.

See Also:
Constant Field Values

DESCRIPTION_DECLARATION

public static final java.lang.String DESCRIPTION_DECLARATION
The description grammar declaration constant.

See Also:
Constant Field Values

GRAMMAR_TYPE_DECLARATION

public static final java.lang.String GRAMMAR_TYPE_DECLARATION
The grammar type grammar declaration constant.

See Also:
Constant Field Values

LICENSE_DECLARATION

public static final java.lang.String LICENSE_DECLARATION
The license grammar declaration constant.

See Also:
Constant Field Values

VERSION_DECLARATION

public static final java.lang.String VERSION_DECLARATION
The version grammar declaration constant.

See Also:
Constant Field Values
Constructor Detail

Grammar

public Grammar(java.io.File file)
        throws java.io.FileNotFoundException,
               GrammarException
Creates a new grammar from the specified file.

Parameters:
file - the grammar file to read
Throws:
java.io.FileNotFoundException - if the grammar file could not be found
GrammarException - if the grammar file could not be parsed and analyzed correctly
Method Detail

createTokenizer

public Tokenizer createTokenizer(java.io.Reader in)
                          throws ParserCreationException
Creates a tokenizer from this grammar.

Parameters:
in - the input stream to use
Returns:
the newly created tokenizer
Throws:
ParserCreationException - if the tokenizer couldn't be created or initialized correctly

createParser

public Parser createParser(Tokenizer tokenizer)
                    throws ParserCreationException
Creates a parser from this grammar.

Parameters:
tokenizer - the tokenizer to use
Returns:
the newly created parser
Throws:
ParserCreationException - if the parser couldn't be created or initialized correctly

getFileName

public java.lang.String getFileName()
Returns the grammar file name.

Returns:
the grammar file name

getDeclaration

public java.lang.String getDeclaration(java.lang.String name)
Returns the declaration value for the specified name.

Parameters:
name - the declaration name
Returns:
the declaration value, or null if not specified in the grammar header

getTokenPatternCount

public int getTokenPatternCount()
Returns the number of token patterns in the grammar.

Returns:
the number of token patterns

getTokenPattern

public TokenPattern getTokenPattern(int pos)
Returns a specific token pattern.

Parameters:
pos - the pattern position, 0 <= pos < count
Returns:
the token pattern

getTokenPattern

public TokenPattern getTokenPattern(java.lang.String name)
Returns a specific token pattern.

Parameters:
name - the pattern name
Returns:
the token pattern

getProductionPatternCount

public int getProductionPatternCount()
Returns the number of production patterns in the grammar.

Returns:
the number of production patterns

getProductionPattern

public ProductionPattern getProductionPattern(int pos)
Returns a specific production pattern.

Parameters:
pos - the pattern position, 0 <= pos < count
Returns:
the production pattern

getProductionPattern

public ProductionPattern getProductionPattern(java.lang.String name)
Returns a specific production pattern.

Parameters:
name - the pattern name
Returns:
the production pattern