net.sourceforge.chaperon.model.grammar
Class Grammar

java.lang.Object
  extended bynet.sourceforge.chaperon.model.grammar.Grammar
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Grammar
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

This class represents a model for a grammar. The content of the grammar includes the productions, start symbol, associativities and priorities.

Version:
CVS $Id: Grammar.java,v 1.16 2003/12/09 19:55:52 benedikta Exp $
Author:
Stephan Michels
See Also:
Serialized Form

Constructor Summary
Grammar()
          Creates an empty grammar.
 
Method Summary
 int addProduction(Production production)
          Add a production to this grammar.
 void addProduction(Production[] list)
          Add a list of productions to this grammar.
 java.lang.Object clone()
          Creates a clone of this grammar.
 boolean contains(Production production)
          If the grammar contains a production.
 boolean contains(Symbol ntsymbol)
          If the grammar contains a production with this nonterminal symbol.
 Associativity getAssociativity(Production production)
          Return the associativity of a production in this grammar.
 Associativity getAssociativity(Terminal terminal)
          Return the associativity of a terminal symbol.
 java.lang.String getLocation()
          Returns the location from the input source.
 int getPriority(Production production)
          Return the priority of a production in this grammar.
 int getPriority(Terminal terminal)
          Returns the priority of a terminal symbol.
 Production[] getProduction()
          Returns the production, which this grammar contains, as an array.
 Production getProduction(int index)
          Return a production giving by an index.
 int getProductionCount()
          Returns the count of productions in this grammar.
 IntegerList getProductionList(Symbol ntsymbol)
          Returns all production for given nonterminal symbol as a list of indices.
 Production[] getProductions(Symbol ntsymbol)
           
 Nonterminal getStartSymbol()
          Return the start symbol.
 SymbolSet getSymbols()
          Return all used symbol in this grammar.
 int indexOf(Production production)
          Return the index of a production.
 int indexOf(Symbol ntsymbol)
          Return the index of the next production, which found by a nonterminal symbol.
 void removeAllProduction()
          Removes all productions from this grammar.
 void removeProduction(int index)
          Removes a production by an index from this grammar.
 void setAssociativity(Terminal terminal, Associativity assoc)
          Set the associativity of a terminal symbol.
 void setLocation(java.lang.String location)
          Set the location from the input source.
 void setPriority(Terminal terminal, int priority)
          Set a priority of a terminal symbol.
 void setProduction(int index, Production production)
          Replace a production by an index in this grammar.
 void setProduction(Production[] productionArray)
          Replace the productions of this grammar by an array of productions.
 void setStartSymbol(Nonterminal startsymbol)
          Set the start symbol for this grammar.
 java.lang.String toString()
          Return a string representation of the grammar.
 Violations validate()
          Validated the grammar.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Grammar

public Grammar()
Creates an empty grammar.

Method Detail

addProduction

public int addProduction(Production production)
Add a production to this grammar.

Parameters:
production - Production, which should be added.
Returns:
Index of the production in this grammar.

addProduction

public void addProduction(Production[] list)
Add a list of productions to this grammar.

Parameters:
list - Array of productions.

removeProduction

public void removeProduction(int index)
Removes a production by an index from this grammar.

Parameters:
index - Index of the production, which should be removed.

setProduction

public void setProduction(int index,
                          Production production)
Replace a production by an index in this grammar.

Parameters:
index - The index, at which the productionshould be replaced.
production - The production.

getProduction

public Production getProduction(int index)
Return a production giving by an index.

Parameters:
index - Index of the Production.
Returns:
The production.

getProductionList

public IntegerList getProductionList(Symbol ntsymbol)
Returns all production for given nonterminal symbol as a list of indices.

Parameters:
ntsymbol - Nonterminal symbol
Returns:
List of indices from the productions

getProductions

public Production[] getProductions(Symbol ntsymbol)

getProductionCount

public int getProductionCount()
Returns the count of productions in this grammar.

Returns:
Count of productions.

indexOf

public int indexOf(Production production)
Return the index of a production.

Parameters:
production - The production.
Returns:
Index of the Production.

indexOf

public int indexOf(Symbol ntsymbol)
Return the index of the next production, which found by a nonterminal symbol.

Parameters:
ntsymbol - Nonterminal symbol
Returns:
Index of the production.

contains

public boolean contains(Production production)
If the grammar contains a production.

Parameters:
production - The production, which the grammar should contain.
Returns:
True, if the grammar contains the production.

contains

public boolean contains(Symbol ntsymbol)
If the grammar contains a production with this nonterminal symbol.

Parameters:
ntsymbol - Nonterminal symbol.
Returns:
True, if the grammar contains a production with the symbol.

removeAllProduction

public void removeAllProduction()
Removes all productions from this grammar.


getProduction

public Production[] getProduction()
Returns the production, which this grammar contains, as an array.

Returns:
Array if productions.

setProduction

public void setProduction(Production[] productionArray)
Replace the productions of this grammar by an array of productions.

Parameters:
productionArray - Array of productions.

setPriority

public void setPriority(Terminal terminal,
                        int priority)
Set a priority of a terminal symbol.

Parameters:
terminal - Terminal symbol.
priority - Priority of the symbol.

getPriority

public int getPriority(Terminal terminal)
Returns the priority of a terminal symbol.

Parameters:
terminal - Terminal symbol.
Returns:
Priority of the symbol.

getPriority

public int getPriority(Production production)
Return the priority of a production in this grammar.

Parameters:
production - Production.
Returns:
Priority of the production.

setAssociativity

public void setAssociativity(Terminal terminal,
                             Associativity assoc)
Set the associativity of a terminal symbol.

Parameters:
terminal - Terminal symbol.
assoc - Associativity of the symbol.

getAssociativity

public Associativity getAssociativity(Terminal terminal)
Return the associativity of a terminal symbol.

Parameters:
terminal - Terminal symbol.
Returns:
Associativity of the symbol.

getAssociativity

public Associativity getAssociativity(Production production)
Return the associativity of a production in this grammar.

Parameters:
production - Production.
Returns:
Associativity of the production.

getSymbols

public SymbolSet getSymbols()
Return all used symbol in this grammar.

Returns:
Set of symbols, which were used.

setStartSymbol

public void setStartSymbol(Nonterminal startsymbol)
Set the start symbol for this grammar.

Parameters:
startsymbol - Start symbol.

getStartSymbol

public Nonterminal getStartSymbol()
Return the start symbol.

Returns:
Start symbol.

setLocation

public void setLocation(java.lang.String location)
Set the location from the input source.

Parameters:
location - Location in the input source.

getLocation

public java.lang.String getLocation()
Returns the location from the input source.

Returns:
Location in the input source.

validate

public Violations validate()
Validated the grammar.

Returns:
Return a list of violations, if this object isn't valid.

toString

public java.lang.String toString()
Return a string representation of the grammar.

Returns:
String representation.

clone

public java.lang.Object clone()
Creates a clone of this grammar.

Returns:
Clone of this grammar.
Throws:
java.lang.CloneNotSupportedException - If an exception occurs during the cloning.


Copyright ? 2003 Chaperon project. All Rights Reserved.