dk.brics.grammar
Class Grammar

java.lang.Object
  extended by dk.brics.grammar.Grammar

public class Grammar
extends Object

Context-free grammar.


Constructor Summary
Grammar(Grammar g)
          Constructs a copy of the given grammar.
Grammar(String start, Collection<Production> productions)
          Constructs a new grammar.
 
Method Summary
 void addProductions(Collection<Production> newprods)
          Adds new productions to this grammar.
 Collection<String> getNonterminals()
          Returns the nonterminals that have productions.
 Production getProduction(ProductionID id)
          Gets production with the given ID.
 Collection<Production> getProductions()
          Returns the productions.
 Collection<Production> getProductions(String nonterminal)
          Gets productions with the given left-hand-side nonterminal.
 String getStart()
          Returns the start nonterminal.
 boolean isUnfolded()
          Returns true if this grammar results from unfolding.
 void setStart(String start)
          Sets the start nonterminal.
 void setUnfolded(boolean unfolded)
          Sets the unfolded status of this grammar (default: false).
 String toString()
          Returns string representation of the productions in this grammar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Grammar

public Grammar(Grammar g)
Constructs a copy of the given grammar. Production objects are cloned.


Grammar

public Grammar(String start,
               Collection<Production> productions)
Constructs a new grammar. Also sets default names for productions and (if no entities are labeled) for entities.

Parameters:
start - start nonterminal
productions - collection of productions
Method Detail

addProductions

public void addProductions(Collection<Production> newprods)
Adds new productions to this grammar.

Parameters:
newprods - new productions

getNonterminals

public Collection<String> getNonterminals()
Returns the nonterminals that have productions.

Returns:
collection of nonterminals

getProduction

public Production getProduction(ProductionID id)
Gets production with the given ID.

Parameters:
id - production ID
Returns:
production

getProductions

public Collection<Production> getProductions()
Returns the productions.

Returns:
collection of productions.

getProductions

public Collection<Production> getProductions(String nonterminal)
Gets productions with the given left-hand-side nonterminal.

Parameters:
nonterminal - nonterminal
Returns:
productions

getStart

public String getStart()
Returns the start nonterminal.

Returns:
nonterminal

isUnfolded

public boolean isUnfolded()
Returns true if this grammar results from unfolding. (Such grammars have expanded alphabet.)

Returns:
true if unfolded

setStart

public void setStart(String start)
Sets the start nonterminal.


setUnfolded

public void setUnfolded(boolean unfolded)
Sets the unfolded status of this grammar (default: false).

Parameters:
unfolded - new unfolded status

toString

public String toString()
Returns string representation of the productions in this grammar. The start nonterminal comes first. Regexp definitions are not included.

Overrides:
toString in class Object


Copyright © 2005-2008 Anders Møller.