ch.uzh.ifi.attempto.chartparser
Class GrammarRule

java.lang.Object
  extended by ch.uzh.ifi.attempto.chartparser.GrammarRule

public class GrammarRule
extends java.lang.Object

This class represents a grammar rule. A grammar rule consists of a nonterminal category (called "head") and a sequence of categories (called "body"). Furthermore, a grammar rule can be scope-closing, which means that all scopes opened by its children are closed at the position after the last child category.

Author:
Tobias Kuhn

Constructor Summary
GrammarRule(Annotation annotation, java.util.List<Category> categories, boolean scopeclosing)
          Creates a new grammar rule.
GrammarRule(Annotation annotation, Nonterminal head, boolean scopeclosing, Category... body)
          Creates a new grammar rule.
GrammarRule(Nonterminal head, boolean scopeclosing, Category... body)
          Creates a new grammar rule.
GrammarRule(Nonterminal head, Category... body)
          Creates a new grammar rule that is not scope-closing.
 
Method Summary
 GrammarRule deepCopy()
          Creates a deep copy of this rule.
 Annotation getAnnotation()
          Returns the annotation object of this rule.
 Category[] getBody()
          Returns the body category sequence of this grammar rule.
 Category getFirst()
          Returns the first category of the body.
 Nonterminal getHead()
          Returns the head category of this grammar rule.
 boolean hasEmptyBody()
          Returns true if the body is empty.
 boolean isScopeClosing()
          Returns true if the rule is scope-closing.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GrammarRule

public GrammarRule(Annotation annotation,
                   Nonterminal head,
                   boolean scopeclosing,
                   Category... body)
Creates a new grammar rule.

Parameters:
annotation - The annotation object.
head - The head category.
scopeclosing - Defines whether the rule is scope-closing or not.
body - The category sequence of the body.

GrammarRule

public GrammarRule(Nonterminal head,
                   boolean scopeclosing,
                   Category... body)
Creates a new grammar rule.

Parameters:
head - The head category.
scopeclosing - Defines whether the rule is scope-closing or not.
body - The category sequence of the body.

GrammarRule

public GrammarRule(Nonterminal head,
                   Category... body)
Creates a new grammar rule that is not scope-closing.

Parameters:
head - The head category.
body - The body category sequence.

GrammarRule

public GrammarRule(Annotation annotation,
                   java.util.List<Category> categories,
                   boolean scopeclosing)
Creates a new grammar rule.

Parameters:
annotation - The annotation object.
categories - The first category of this list stands for the head category (it has to be a Nonterminal object). The rest stands for the body categories.
scopeclosing - Defines whether the rule is scope-closing or not.
Method Detail

getHead

public Nonterminal getHead()
Returns the head category of this grammar rule.

Returns:
The head category.

getBody

public Category[] getBody()
Returns the body category sequence of this grammar rule.

Returns:
The body category sequence.

hasEmptyBody

public boolean hasEmptyBody()
Returns true if the body is empty. Such grammar rules are called "epsilon rules".

Returns:
true if the body is empty.

getFirst

public Category getFirst()
Returns the first category of the body.

Returns:
The first category of the body.

isScopeClosing

public boolean isScopeClosing()
Returns true if the rule is scope-closing.

Returns:
true if the rule is scope-closing.

getAnnotation

public Annotation getAnnotation()
Returns the annotation object of this rule.

Returns:
The annotation object.

deepCopy

public GrammarRule deepCopy()
Creates a deep copy of this rule.

Returns:
A deep copy.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright 2008-2012, AceWiki developers