Class SentenceParser
java.lang.Object
org.projog.core.parser.SentenceParser
Parses Prolog syntax representing rules including operators.
Note: not thread safe.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final Tokenprivate final Operandsprivate final TokenParserA collection ofVariables this parser currently knows about (key = the variable name). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SentenceParsergetInstance(Reader reader, Operands operands) Returns a newSentenceParserthat will parse Prolog syntax read from the specifiedReaderusing the specifiedOperands.static SentenceParsergetInstance(String prologSyntax, Operands operands) Returns a newSentenceParserwill parse the specifiedStringusing the specifiedOperands.private VariableReturns collection ofVariableinstances created by thisSentenceParser.private ParserExceptionnewParserException(String message) Returns a newParserExceptionwith the specified message.private Tokenprivate TokenparsePredicate(Token next) private TokenparseToken(boolean rewindOnTermination, Function<Token, Boolean> terminationCriteria) parseTokens(boolean rewindOnTermination, Function<Token, Boolean> terminationCriteria) private DecimalFractiontoDecimalFraction(String value) private IntegerNumbertoIntegerNumber(String value) private Termprivate TokentoSingleToken(Token[] tokens, int startIdx, int endIdx, int previousPriority, boolean faiIfPriorityEqual) private TermtoStructureFromNamedBracket(Token token) private Termprivate Term
-
Field Details
-
COMMA_PRIORITY
private static final int COMMA_PRIORITY- See Also:
-
EMPTY_LIST_TOKEN
-
parser
-
operands
-
variables
A collection ofVariables this parser currently knows about (key = the variable name).The reason this information needs to be stored is so that each instance of the same variable name, in a single sentence, refers to the same
Variableinstance.e.g. During the parsing of the sentence
Y is 2, X is Y * 2.twoVariableinstances need to be created - one for the variable nameXand one that is shared between both references to the variable nameY.
-
-
Constructor Details
-
SentenceParser
-
-
Method Details
-
getInstance
Returns a newSentenceParserwill parse the specifiedStringusing the specifiedOperands.- Parameters:
prologSyntax- the prolog syntax to be parsedoperands- details of the operands to use during parsing- Returns:
- a new
SentenceParser
-
getInstance
Returns a newSentenceParserthat will parse Prolog syntax read from the specifiedReaderusing the specifiedOperands.- Parameters:
reader- the source of the prolog syntax to be parsedoperands- details of the operands to use during parsing- Returns:
- a new
SentenceParser
-
getParsedTermVariables
Returns collection ofVariableinstances created by thisSentenceParser.Returns all
Variables created by thisSentenceParsereither since it was created or since the last execution ofparseSentence().- Returns:
- collection of
Variableinstances created by thisSentenceParser
-
parseSentence
- Returns:
- a
Termcreated from Prolog syntax read from this object'sCharacterParserornullif the end of the underlying stream being parsed has been reached - Throws:
ParserException- if an error parsing the Prolog syntax occurs
-
parseToken
-
parseTokens
-
parseList
-
parsePredicate
-
toSingleToken
-
toTerm
-
toStructureFromNamedBracket
-
toStructureFromOperandAndArguments
-
toList
-
toIntegerNumber
-
toDecimalFraction
-
getOrCreateVariable
-
newParserException
Returns a newParserExceptionwith the specified message.
-