Package org.nineml.coffeegrinder.parser
Class EarleyParser
java.lang.Object
org.nineml.coffeegrinder.parser.EarleyParser
- All Implemented Interfaces:
GearleyParser
The Earley parser.
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.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the column number of the last character on the last line read by the parser.Get the grammar used by this parser.int
Returns the line number of the last line read by the parser.int
Returns the last offset read by the parser.Return the parser type.getSeed()
Get theNonterminalSymbol
seed value used by this parser.boolean
Is there more input?Parse an input string against the grammar.Parse a sequence of tokens against the grammar.Parse an array of tokens against the grammar.
-
Field Details
-
logcategory
- See Also:
-
-
Method Details
-
getParserType
Return the parser type.- Specified by:
getParserType
in interfaceGearleyParser
- Returns:
ParserType.Earley
-
getGrammar
Get the grammar used by this parser.- Specified by:
getGrammar
in interfaceGearleyParser
- Returns:
- the grammar
-
getSeed
Get theNonterminalSymbol
seed value used by this parser.- Specified by:
getSeed
in interfaceGearleyParser
- Returns:
- the seed
-
parse
Parse an input string against the grammar.This is a shortcut for parsing a sequence of characters.
- Specified by:
parse
in interfaceGearleyParser
- Parameters:
input
- the input string- Returns:
- a parse result
-
parse
Parse an array of tokens against the grammar.You must not change the input array.
- Specified by:
parse
in interfaceGearleyParser
- Parameters:
input
- the input array- Returns:
- a parse result
-
parse
Parse a sequence of tokens against the grammar.- Specified by:
parse
in interfaceGearleyParser
- Parameters:
input
- the input sequence- Returns:
- a parse result
-
hasMoreInput
public boolean hasMoreInput()Is there more input?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.
- Specified by:
hasMoreInput
in interfaceGearleyParser
- Returns:
- true if parsing failed before the entire input was consumed
-
getLineNumber
public int getLineNumber()Description copied from interface:GearleyParser
Returns the line number of the last line read by the parser.- Specified by:
getLineNumber
in interfaceGearleyParser
- Returns:
- the line number.
-
getColumnNumber
public int getColumnNumber()Description copied from interface:GearleyParser
Returns the column number of the last character on the last line read by the parser.- Specified by:
getColumnNumber
in interfaceGearleyParser
- Returns:
- the column number.
-
getOffset
public int getOffset()Description copied from interface:GearleyParser
Returns the last offset read by the parser.- Specified by:
getOffset
in interfaceGearleyParser
- Returns:
- the offset.
-