public class EarleyParser extends java.lang.Object implements GearleyParser
The Earley parser compares an input sequence against a grammar and determines if the input is a sentence in the grammar.
This is a fairly literal implementation of the parser in ยง5 of SPPF-Style Parsing From Earley Recognisers.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
logcategory |
Modifier and Type | Method and Description |
---|---|
int |
getColumnNumber()
Returns the column number of the last character on the last line read by the parser.
|
ParserGrammar |
getGrammar()
Get the grammar used by this parser.
|
int |
getLineNumber()
Returns the line number of the last line read by the parser.
|
int |
getOffset()
Returns the last offset read by the parser.
|
ParserType |
getParserType()
Return the parser type.
|
NonterminalSymbol |
getSeed()
Get the
NonterminalSymbol seed value used by this parser. |
boolean |
hasMoreInput()
Is there more input?
|
EarleyResult |
parse(java.util.Iterator<Token> input)
Parse a sequence of tokens against the grammar.
|
EarleyResult |
parse(java.lang.String input)
Parse an input string against the grammar.
|
EarleyResult |
parse(Token[] input)
Parse an array of tokens against the grammar.
|
public static final java.lang.String logcategory
public ParserType getParserType()
getParserType
in interface GearleyParser
ParserType.Earley
public ParserGrammar getGrammar()
getGrammar
in interface GearleyParser
public NonterminalSymbol getSeed()
NonterminalSymbol
seed value used by this parser.getSeed
in interface GearleyParser
public EarleyResult parse(java.lang.String input)
This is a shortcut for parsing a sequence of characters.
parse
in interface GearleyParser
input
- the input stringpublic EarleyResult parse(Token[] input)
You must not change the input array.
parse
in interface GearleyParser
input
- the input arraypublic EarleyResult parse(java.util.Iterator<Token> input)
parse
in interface GearleyParser
input
- the input sequencepublic boolean hasMoreInput()
If the parse succeeded, the answer will always be false. But a failed parse can fail because it was unable to process a token or because it ran out of tokens. This method checks if there was any more input after the parse completed.
hasMoreInput
in interface GearleyParser
public int getLineNumber()
GearleyParser
getLineNumber
in interface GearleyParser
public int getColumnNumber()
GearleyParser
getColumnNumber
in interface GearleyParser
public int getOffset()
GearleyParser
getOffset
in interface GearleyParser