Pep 0.4 API Documentation

edu.osu.ling.pep
Class Grammar

java.lang.Object
  extended by edu.osu.ling.pep.Grammar

public class Grammar
extends Object

Represents a context-free grammar (set of production rules).

Grammars maintain their rules indexed by left side category. The rule sets contained for any given left category are not guaranteed to be maintained in the order of insertion.

Version:
$LastChangedRevision: 1781 $
Author:
Scott Martin

Constructor Summary
Grammar(String name)
          Creates a grammar with the given name, initializes its internal data structure.
 
Method Summary
 boolean addRule(Rule rule)
          Adds a production rule.
 boolean containsRules(Category left)
          Tests whether this grammar contains rules for the specified left side category.
 Set<Rule> getAllRules()
          Gets every rule in this grammar.
 String getName()
          Gets the name of this grammar.
 Set<Rule> getRules(Category left)
          Gets the set of rules contained by this grammar with the given left side category.
 String toString()
          Gets a string representation of this grammar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Grammar

public Grammar(String name)
Creates a grammar with the given name, initializes its internal data structure.

Parameters:
name - The mnemonic name for this grammar.
Method Detail

addRule

public boolean addRule(Rule rule)
Adds a production rule. If no rules are contained for the left side of the specified rule, a new rule set is created.

Parameters:
rule - The rule to add.
Returns:
true iff this grammar did not already contain the specified rule.
Throws:
NullPointerException - If rule is null.

containsRules

public boolean containsRules(Category left)
Tests whether this grammar contains rules for the specified left side category.

Parameters:
left - The left category of the rules to test for.
Returns:
true iff this grammar contains rules with the specified category as their left side.

getAllRules

public Set<Rule> getAllRules()
Gets every rule in this grammar.


getName

public String getName()
Gets the name of this grammar.

Returns:
The value specified when this grammar was created.

getRules

public Set<Rule> getRules(Category left)
Gets the set of rules contained by this grammar with the given left side category.

Parameters:
left - The left side of the rules to find.
Returns:
A set containing the rules in this grammar whose left side is the same as left, or null if no such rules are contained in this grammar. The rule set returned by this method is not guaranteed to contain the rules in the order in which they were added.

toString

public String toString()
Gets a string representation of this grammar.

Overrides:
toString in class Object
Returns:
A string listing all of the rules contained by this grammar.
See Also:
Rule.toString()

Pep: Pep is an Earley parser

Pep API Documentation, Copyright © 2007 Scott Martin

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the overview file.