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.


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 and path.
 ProductionPattern getProductionPattern(int pos)
          Returns a specific production pattern.
 ProductionPattern getProductionPatternById(int id)
          Returns a production pattern identified by its id.
 ProductionPattern getProductionPatternByName(java.lang.String name)
          Returns a production pattern identified by its name.
 int getProductionPatternCount()
          Returns the number of production patterns in the grammar.
 TokenPattern getTokenPattern(int pos)
          Returns a specific token pattern.
 TokenPattern getTokenPatternById(int id)
          Returns a token pattern identified by its id.
 TokenPattern getTokenPatternByName(java.lang.String name)
          Returns a token pattern identified by its name.
 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,
               ParserLogException,
               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
ParserLogException - if the grammar file couldn't be parsed correctly
GrammarException - if the grammar wasn't valid
Method Detail

createTokenizer

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

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

createParser

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

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

getFileName

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

Returns:
the grammar file name and path

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

getTokenPatternById

public TokenPattern getTokenPatternById(int id)
Returns a token pattern identified by its id.

Parameters:
id - the pattern id
Returns:
the token pattern, or null

getTokenPatternByName

public TokenPattern getTokenPatternByName(java.lang.String name)
Returns a token pattern identified by its name.

Parameters:
name - the pattern name
Returns:
the token pattern, or null

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

getProductionPatternById

public ProductionPattern getProductionPatternById(int id)
Returns a production pattern identified by its id.

Parameters:
id - the pattern id
Returns:
the production pattern, or null

getProductionPatternByName

public ProductionPattern getProductionPatternByName(java.lang.String name)
Returns a production pattern identified by its name.

Parameters:
name - the pattern name
Returns:
the production pattern, or null