ch.uzh.ifi.attempto.chartparser
Class ChartParser

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

public class ChartParser
extends java.lang.Object

This is a chart parser (concretely an Earley parser) fully implemented in Java. However, there is a Prolog format ("Attempto Chartparser Grammar Notation" or "ACGN") that can be transformed into Java (at compile time).

Author:
Tobias Kuhn
See Also:
Grammar

Constructor Summary
ChartParser(Grammar grammar)
          Creates a new chart parser for the given grammar.
 
Method Summary
 void addToken(Terminal... token)
          Adds the token to the token sequence and makes one more parsing step to process it.
 void addTokens(java.util.List<Terminal> tokens)
          Adds the tokens to the token sequence and processes them.
 void debug(boolean debug)
          This method can be used to switch on/off debug mode (default is off).
 boolean[] getAccessiblePositions(java.lang.String nextToken)
          Returns a boolean array that describes which of the tokens of the current token sequence are accessible (true) and which are not (false) for the given next token.
 java.util.List<java.lang.Object> getTokens()
          Returns the current token sequence.
 java.util.List<Terminal> nextTokens()
          Returns all tokens that are allowed to follow the current token sequence according to the grammar.
 void removeAllTokens()
          Removes all tokens in the current token sequence and resets the chart.
 void removeToken()
          Removes the last token and reverts the last parsing step.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChartParser

public ChartParser(Grammar grammar)
Creates a new chart parser for the given grammar. The grammar must not be changed afterwards.

Parameters:
grammar - The grammar to be used by the chart parser.
Method Detail

debug

public void debug(boolean debug)
This method can be used to switch on/off debug mode (default is off). In debug mode, messages about the actions of the chart parser are printed onto the standard error device.

Parameters:
debug - true to switch on debug mode or false to switch it off.

addToken

public void addToken(Terminal... token)
Adds the token to the token sequence and makes one more parsing step to process it. If several tokens are given then these tokens are treated in a parallel way representing a token that can have multiple forms.

Parameters:
token - The token to be added to the token sequence.

addTokens

public void addTokens(java.util.List<Terminal> tokens)
Adds the tokens to the token sequence and processes them.

Parameters:
tokens - The tokens to be added to the token sequence.

removeToken

public void removeToken()
Removes the last token and reverts the last parsing step.


removeAllTokens

public void removeAllTokens()
Removes all tokens in the current token sequence and resets the chart.


getTokens

public java.util.List<java.lang.Object> getTokens()
Returns the current token sequence. The elements of the list are strings (in the normal case) or arrays of strings (in the case of parallel tokens).

Returns:
The current token sequence.

nextTokens

public java.util.List<Terminal> nextTokens()
Returns all tokens that are allowed to follow the current token sequence according to the grammar.

Returns:
The possible next tokens.

getAccessiblePositions

public boolean[] getAccessiblePositions(java.lang.String nextToken)
Returns a boolean array that describes which of the tokens of the current token sequence are accessible (true) and which are not (false) for the given next token.

Parameters:
nextToken - The next token for which the tokens should be checked for accessibility.
Returns:
A boolean array where each element stands for one token of the token sequence.


Copyright 2008-2009, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch)