Class 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