Class DelpParser
- All Implemented Interfaces:
DelpParserConstants
THEORY ::== (EXPRESSION)+ EXPRESSION ::== FACT | STRICTRULE | DEFEASIBLERULE FACT ::== LITERAL + "." STRICTRULE ::== LITERAL + "<-" + RULEBODY + "." DEFEASIBLERULE ::== LITERAL + "-<" + RULEBODY + "." RULEBODY ::== LITERAL | LITERAL + "," + RULEBODY LITERAL ::== "~" + ATOM | ATOM ATOM ::== PREDICATE | PREDICATE + "(" + TERMLIST + ")" TERMLIST ::== TERM | TERM + "," + TERMLIST TERM ::== VARIABLE | CONSTANT | QUOTED_STRING PREDICATE is a sequence of symbols from {a,...,z,A,...,Z,0,...,9,_,-} with a letter at the beginning. VARIABLE is a sequence of symbols from {a,...,z,A,...,Z,0,...,9,_,-} with an uppercase letter at the beginning. CONSTANT is a sequence of symbols from {a,...,z,A,...,Z,0,...,9,_,-} with an lowercase letter at the beginning. QUOTED_STRING is all characters between double quotes.
-
Field Summary
Modifier and TypeFieldDescriptionNext token.Current token.Generated Token Manager.Fields inherited from interface org.tweetyproject.arg.delp.parser.DelpParserConstants
DEFAULT, EOF, NAME, QUOTED, tokenImage
-
Constructor Summary
ConstructorDescriptionConstructs a new `DelpParser` instance with an empty input reader.DelpParser
(InputStream stream) Creates a new parser instance with the specified input stream.DelpParser
(InputStream stream, String encoding) Creates a new parser instance with the specified input stream and character encoding.DelpParser
(Reader stream) Creates a new parser instance with the specified reader.Creates a new parser instance with the specified token manager. -
Method Summary
Modifier and TypeMethodDescriptionfinal FolAtom
Atom
(DefeasibleLogicProgram delp, FolSignature signature) Parses an atom (predicate with optional terms) from the input.final void
Disable tracing.final void
Enable tracing.final void
Expression
(DefeasibleLogicProgram delp, FolSignature signature) Parses an expression in the defeasible logic program.final FolFormula
Formula
(FolSignature signature) Parses a formula from the given signature.Generate ParseException.final Token
Retrieves the next token in the input stream.Return the signaturefinal Token
getToken
(int index) Retrieves a specific token from the input stream by its index.final FolFormula
Literal
(DefeasibleLogicProgram delp, FolSignature signature) Parses a literal, which could be an atom or its negation.parseBeliefBase
(Reader reader) Parses a defeasible logic program from the given reader.parseFormula
(Reader reader) A formula here is a Literal, that is an Atom or a negated Atom.void
ReInit
(InputStream stream) Reinitializes the parser with a new input stream.void
ReInit
(InputStream stream, String encoding) Reinitializes the parser with a new input stream and character encoding.void
Reinitializes the parser with a new reader.void
Reinitializes the parser with a new token manager.final Term
Term
(DefeasibleLogicProgram delp, FolSignature signature) Parses a term (either a variable or a constant) from the input.final DefeasibleLogicProgram
Theory
(FolSignature signature) Parses a defeasible logic program from a given signature.Methods inherited from class org.tweetyproject.commons.Parser
isNumeric, parseBeliefBase, parseBeliefBaseFromFile, parseFormula, parseFormulaFromFile, parseListOfBeliefBases, parseListOfBeliefBases, parseListOfBeliefBasesFromFile, parseListOfBeliefBasesFromFile
-
Field Details
-
token_source
Generated Token Manager. -
token
Current token. -
jj_nt
Next token.
-
-
Constructor Details
-
DelpParser
public DelpParser()Constructs a new `DelpParser` instance with an empty input reader. -
DelpParser
Creates a new parser instance with the specified input stream.- Parameters:
stream
- The input stream to be used by the parser.
-
DelpParser
Creates a new parser instance with the specified input stream and character encoding.- Parameters:
stream
- The input stream to be used by the parser.encoding
- The character encoding of the input stream. Ifnull
, the default encoding is used.
-
DelpParser
Creates a new parser instance with the specified reader.- Parameters:
stream
- The reader to be used by the parser.
-
DelpParser
Creates a new parser instance with the specified token manager.- Parameters:
tm
- The token manager to be used by the parser.
-
-
Method Details
-
parseBeliefBase
Parses a defeasible logic program from the given reader.This method initializes the parser with the provided reader and parses the input to construct a
DefeasibleLogicProgram
. It uses the current logical signature to guide the parsing process.- Specified by:
parseBeliefBase
in classParser<DefeasibleLogicProgram,
Formula> - Parameters:
reader
- The reader from which the defeasible logic program is read.- Returns:
- A
DefeasibleLogicProgram
constructed from the input. - Throws:
ParserException
- If an error occurs during parsing.
-
parseFormula
A formula here is a Literal, that is an Atom or a negated Atom. The class DelpQuery encapsulates the following. The Atom is either a DeLP predicate (a predicate with arity > 0) or a DeLP constant or variable (a predicate with arity == 0). In the case of a real predicate, test all arguments whether they are DeLP variables (= begin with upper case letter) or DeLP constants. All predicates and constants need to be present in the current signature to parse.- Specified by:
parseFormula
in classParser<DefeasibleLogicProgram,
Formula> - Parameters:
reader
- the reader to parse from- Returns:
- a Formula, which is always a DelpQuery in this implementation, that has been successfully parsed with the current signature in mind
- Throws:
ParserException
- if the reader cannot be successfully parsed into a formula
-
getSignature
-
Theory
Parses a defeasible logic program from a given signature.- Parameters:
signature
- The signature that defines the vocabulary of the logic program.- Returns:
- A
DefeasibleLogicProgram
instance representing the parsed program. - Throws:
ParseException
- If an error occurs during parsing.
-
Expression
public final void Expression(DefeasibleLogicProgram delp, FolSignature signature) throws ParseException Parses an expression in the defeasible logic program.- Parameters:
delp
- The defeasible logic program to which parsed components are added.signature
- The signature that defines the vocabulary of the logic program.- Throws:
ParseException
- If an error occurs during parsing.
-
Formula
Parses a formula from the given signature.- Parameters:
signature
- The signature that defines the vocabulary of the logic program.- Returns:
- A
FolFormula
representing the parsed formula. - Throws:
ParseException
- If an error occurs during parsing.
-
Literal
public final FolFormula Literal(DefeasibleLogicProgram delp, FolSignature signature) throws ParseException Parses a literal, which could be an atom or its negation.- Parameters:
delp
- The defeasible logic program to which the literal might be added.signature
- The signature that defines the vocabulary of the logic program.- Returns:
- A
FolFormula
representing the parsed literal. - Throws:
ParseException
- If an error occurs during parsing.
-
Atom
public final FolAtom Atom(DefeasibleLogicProgram delp, FolSignature signature) throws ParseException Parses an atom (predicate with optional terms) from the input.This method constructs a
FolAtom
by parsing a predicate name followed by a sequence of terms, if present. The predicate is added to the signature if it is not already present, and its arity is checked for correctness. If the arity is incorrect, aParseException
is thrown.- Parameters:
delp
- The defeasible logic program to which the predicate might be added.signature
- The logical signature to which the predicate might be added.- Returns:
- A
FolAtom
constructed from the parsed predicate and terms. - Throws:
ParseException
- If an error occurs during parsing, such as an incorrect predicate arity.
-
Term
Parses a term (either a variable or a constant) from the input.This method constructs a
Term
based on the input token. It handles variables (identified by uppercase names) and constants (both plain and quoted). If a quoted term is encountered, the quotes are removed before creating the constant.- Parameters:
delp
- The defeasible logic program used for creating constants (if needed).signature
- The logical signature used for creating constants (if needed).- Returns:
- A
Term
constructed from the parsed token. - Throws:
ParseException
- If an error occurs during parsing.
-
ReInit
Reinitializes the parser with a new input stream.- Parameters:
stream
- The new input stream to be used by the parser.
-
ReInit
Reinitializes the parser with a new input stream and character encoding.- Parameters:
stream
- The new input stream to be used by the parser.encoding
- The character encoding of the new input stream. Ifnull
, the default encoding is used.
-
ReInit
Reinitializes the parser with a new reader.- Parameters:
stream
- The new reader to be used by the parser.
-
ReInit
Reinitializes the parser with a new token manager.- Parameters:
tm
- The new token manager to be used by the parser.
-
getNextToken
Retrieves the next token in the input stream.This method advances to the next token by either using the previously cached next token or fetching a new token from the token source if there is no cached next token. The token stream is updated and the token index and generation are incremented accordingly.
- Returns:
- The next
Token
in the input stream.
-
getToken
Retrieves a specific token from the input stream by its index.This method traverses the token stream to reach the token at the specified index. If the token at the given index is not already available, it fetches the necessary tokens from the token source until the desired token is reached.
- Parameters:
index
- The zero-based index of the token to retrieve.- Returns:
- The
Token
at the specified index in the input stream.
-
generateParseException
-
enable_tracing
public final void enable_tracing()Enable tracing. -
disable_tracing
public final void disable_tracing()Disable tracing.
-