Package net.sf.tweety.lp.asp.parser
Class ASPCore2Parser
- java.lang.Object
-
- net.sf.tweety.lp.asp.parser.ASPCore2Parser
-
- All Implemented Interfaces:
ASPCore2ParserConstants
,ASPCore2ParserTreeConstants
public class ASPCore2Parser extends java.lang.Object implements ASPCore2ParserTreeConstants, ASPCore2ParserConstants
Parser for ASP programs in the ASP-Core-2 syntax https://www.mat.unical.it/aspcomp2013/files/ASP-CORE-2.03c.pdf. This parser also supports most of the (Clingo) and DLV input syntaxes and provides additional methods for parsing answer sets given by the DLV and Clingo solvers.
The EBNF grammar for ASP-Core-2 is given as follows:
PROGRAM ::== (STATEMENT)* (QUERY)?
QUERY ::== LITERAL "?"
STATEMENT ::== ":-" BODY_ELEMENTS "." | HEAD (":-" BODY_ELEMENTS)? "." | ":~" BODY_ELEMENTS "." | OPTIMIZE "."
HEAD ::== (LITERAL "|")* LITERAL | CHOICE
BODY_ELEMENTS ::== (BODY_ELEMENTS ",")? BODY_ELEMENT
BODY_ELEMENT ::== NAF_LITERAL | ("not")? AGGREGATE
CHOICE ::== (TERM BINOP)? "{" CHOICE_ELEMENTS "}" (BINOP TERM)?
CHOICE_ELEMENTS ::== (CHOICE_ELEMENTS ";")? CHOICE_ELEMENT
CHOICE_ELEMENT ::== LITERAL (":" NAF_LITERALS)?
AGGREGATE ::== (TERM BINOP)? AGGREGATE_FUNCTION "{" AGGREGATE_ELEMENTS "}" (BINOP TERM)?
AGGREGATE_ELEMENTS ::== (AGGREGATE_ELEMENTS ";")? AGGREGATE_ELEMENT
AGGREGATE_ELEMENT ::== (Terms)? (":" NAF_LITERALS)?
AGGREGATE_FUNCTION ::== "#max" | "#min" | "#count" | "#sum"
OPTIMIZE ::== OPTIMIZE_FUNCTION "{" (OPTIMIZE_ELEMENTS)? "}"
OPTIMIZE_ELEMENTS ::== (OPTIMIZE_ELEMENTS ";")? OPTIMIZE_ELEMENT
OPTIMIZE_ELEMENT ::== WEIGHT_AT_LEVEL (":" NAF_LITERALS)?
OPTIMIZE_FUNCTION ::== "#maximize" | "#maximise" | "#minimize"| "#minimise"
WEIGHT_AT_LEVEL ::== TERM ("@" TERM)? ("," TERMS)?
NAF_LITERALS ::== (NAF_LITERALS ",")? NAF_LITERAL
NAF_LITERAL ::== ("not")? LITERAL | BUILTIN_ATOM
LITERAL ::== ("-")? ID ("(" Terms ")")?
BUILTIN_ATOM ::== TERM BINOP TERM
BINOP ::== "=" | "!=" | "<>" | "<" | ">" | "<=" | ">="
TERMS ::== (TERMS ",")? TERM
TERM ::== ID ("(" TERMS ")")? | NUMBER | STRING | VARIABLE | "_" | "(" TERM ")" | "-" TERM | TERM ARITHOP TERM
ARITHOP ::== "+" | "-" | "*" | "/"
where ID is a sequence of letters, numbers, and "_" that starts with a lowercase letter, VARIABLE is a sequence of letters, numbers, and "_" that starts with an uppercase letter, STRING is a sequence of arbitrary characters surrounded by quotation marks ("...") and NUMBER is a sequence of numbers.
Single-line comments (starting with "%") and multi-line-comments (starting with "%*", ending with "*%") are ignored by the parser.
The following constructs from Clingo are supported additionally to the ASP-Core-2 syntax:
- show statements: "#show " ID "/" NUMBER
Other Clingo meta-statements (#include, #external, #program, #script and #const) are currently not supported.
The following constructs from DLV are supported additionally to the ASP-Core-2 syntax:
- TODO- Author:
- Anna Gessler
-
-
Field Summary
Fields Modifier and Type Field Description Token
jj_nt
Next token.Token
token
Current token.ASPCore2ParserTokenManager
token_source
Generated Token Manager.-
Fields inherited from interface net.sf.tweety.lp.asp.parser.ASPCore2ParserConstants
AGGREGATE_COUNT, AGGREGATE_MAX, AGGREGATE_MIN, AGGREGATE_SUM, ANONYMOUS_VARIABLE, AT, CLINGO_SHOW, COLON, COMMA, COMMENT, CONS, CURLY_CLOSE, CURLY_OPEN, DEFAULT, DIV, DOT, EOF, EQUAL, GREATER, GREATER_OR_EQ, ID, LESS, LESS_OR_EQ, MAXIMIZE, MINIMIZE, MINUS, MULTI_LINE_COMMENT, NAF, NUMBER, OR, PAREN_CLOSE, PAREN_OPEN, PLUS, QUERY_MARK, SEMICOLON, SQUARE_CLOSE, SQUARE_OPEN, STRING, TIMES, tokenImage, UNEQUAL, VARIABLE, WCONS
-
Fields inherited from interface net.sf.tweety.lp.asp.parser.ASPCore2ParserTreeConstants
JJTAGGREGATE, JJTAGGRELEMENT, JJTAGGRELEMENTLIST, JJTAGGRFUNC, JJTANSWERSET, JJTARITERM, JJTARITHOP, JJTBINOP, JJTBODY, JJTBODYLIST, JJTBUILTINATOM, JJTCHOICE, JJTCHOICEELEMENT, JJTCHOICEELEMENTLIST, JJTCLINGOMETA, JJTHEAD, JJTHEADELEMENTSLIST, JJTID, JJTLITERAL, JJTNAFLITERAL, JJTNAFLITERALLIST, jjtNodeName, JJTNUMBER, JJTOPT, JJTOPTELEMENT, JJTOPTELEMENTLIST, JJTOPTFUNC, JJTPROGRAM, JJTQUERY, JJTRULE, JJTRULELIST, JJTSTRING, JJTTERM, JJTTERMLIST, JJTVAR, JJTWEIGHT
-
-
Constructor Summary
Constructors Constructor Description ASPCore2Parser(java.io.InputStream stream)
ASPCore2Parser(java.io.InputStream stream, java.lang.String encoding)
ASPCore2Parser(java.io.Reader stream)
ASPCore2Parser(ASPCore2ParserTokenManager tm)
-
Method Summary
-
-
-
Field Detail
-
token_source
public ASPCore2ParserTokenManager token_source
Generated Token Manager.
-
token
public Token token
Current token.
-
jj_nt
public Token jj_nt
Next token.
-
-
Constructor Detail
-
ASPCore2Parser
public ASPCore2Parser(java.io.InputStream stream)
-
ASPCore2Parser
public ASPCore2Parser(java.io.InputStream stream, java.lang.String encoding)
-
ASPCore2Parser
public ASPCore2Parser(java.io.Reader stream)
-
ASPCore2Parser
public ASPCore2Parser(ASPCore2ParserTokenManager tm)
-
-
Method Detail
-
parseProgram
public static Program parseProgram(java.lang.String program) throws ParseException
- Throws:
ParseException
-
parseProgram
public static Program parseProgram(java.io.Reader reader) throws ParseException
- Throws:
ParseException
-
parseRule
public static ASPRule parseRule(java.lang.String rule) throws ParseException
- Throws:
ParseException
-
parseRule
public static ASPRule parseRule(java.io.Reader reader) throws ParseException
- Throws:
ParseException
-
parseAnswerSet
public static AnswerSet parseAnswerSet(java.lang.String answerSet) throws ParseException
- Throws:
ParseException
-
parseAnswerSet
public static AnswerSet parseAnswerSet(java.io.Reader reader) throws ParseException
- Throws:
ParseException
-
AnswerSet
public final ASTAnswerSet AnswerSet() throws ParseException
- Throws:
ParseException
-
Program
public final ASTProgram Program() throws ParseException
- Throws:
ParseException
-
Statements
public final ASTRuleList Statements() throws ParseException
- Throws:
ParseException
-
Query
public final ASTQuery Query() throws ParseException
- Throws:
ParseException
-
Statement
public final ASTRule Statement() throws ParseException
- Throws:
ParseException
-
Head
public final ASTHead Head() throws ParseException
- Throws:
ParseException
-
Body
public final ASTBodyList Body() throws ParseException
- Throws:
ParseException
-
Body1
public final ASTBody Body1() throws ParseException
- Throws:
ParseException
-
Disjunction
public final ASTHeadElementsList Disjunction() throws ParseException
- Throws:
ParseException
-
Choice
public final ASTChoice Choice() throws ParseException
- Throws:
ParseException
-
ChoiceElements
public final ASTChoiceElementList ChoiceElements() throws ParseException
- Throws:
ParseException
-
ChoiceElement
public final ASTChoiceElement ChoiceElement() throws ParseException
- Throws:
ParseException
-
Aggregate
public final ASTAggregate Aggregate() throws ParseException
- Throws:
ParseException
-
AggregateElements
public final ASTAggrElementList AggregateElements() throws ParseException
- Throws:
ParseException
-
AggregateElement
public final ASTAggrElement AggregateElement() throws ParseException
- Throws:
ParseException
-
AggregateFunction
public final java.lang.String AggregateFunction() throws ParseException
- Throws:
ParseException
-
ClingoMetaStatement
public final void ClingoMetaStatement() throws ParseException
- Throws:
ParseException
-
Optimize
public final ASTOpt Optimize() throws ParseException
- Throws:
ParseException
-
OptimizeElements
public final ASTOptElementList OptimizeElements() throws ParseException
- Throws:
ParseException
-
OptimizeElement
public final ASTOptElement OptimizeElement() throws ParseException
- Throws:
ParseException
-
OptimizeFunction
public final java.lang.String OptimizeFunction() throws ParseException
- Throws:
ParseException
-
WeightAtLevel
public final ASTWeight WeightAtLevel() throws ParseException
- Throws:
ParseException
-
NAFLiterals
public final ASTNAFLiteralList NAFLiterals() throws ParseException
- Throws:
ParseException
-
NAFLiteral
public final ASTNAFLiteral NAFLiteral() throws ParseException
- Throws:
ParseException
-
ClassicalLiteral
public final ASTLiteral ClassicalLiteral() throws ParseException
- Throws:
ParseException
-
BuiltinAtom
public final ASTBuiltInAtom BuiltinAtom() throws ParseException
- Throws:
ParseException
-
Binop
public final java.lang.String Binop() throws ParseException
- Throws:
ParseException
-
Terms
public final ASTTermList Terms() throws ParseException
- Throws:
ParseException
-
Term
public final ASTTerm Term() throws ParseException
- Throws:
ParseException
-
AriTerm
public final ASTAriTerm AriTerm() throws ParseException
- Throws:
ParseException
-
Arithop
public final java.lang.String Arithop() throws ParseException
- Throws:
ParseException
-
Number
public final void Number() throws ParseException
- Throws:
ParseException
-
Variable
public final void Variable() throws ParseException
- Throws:
ParseException
-
Identifier
public final void Identifier() throws ParseException
- Throws:
ParseException
-
String
public final void String() throws ParseException
- Throws:
ParseException
-
ReInit
public void ReInit(java.io.InputStream stream)
-
ReInit
public void ReInit(java.io.InputStream stream, java.lang.String encoding)
-
ReInit
public void ReInit(java.io.Reader stream)
-
ReInit
public void ReInit(ASPCore2ParserTokenManager tm)
-
getNextToken
public final Token getNextToken()
-
getToken
public final Token getToken(int index)
-
generateParseException
public ParseException generateParseException()
-
enable_tracing
public final void enable_tracing()
Enable tracing.
-
disable_tracing
public final void disable_tracing()
Disable tracing.
-
-