Class ActionQueryParser


  • public class ActionQueryParser
    extends Parser<SActionQuerySet,​SActionQuery>
    This class implements a parser for action queries in S. The BNF of such queries is given by: (starting symbol is KB)
    KB ::== QUERY1 ("\n" QUERY1)*
    QUERY1 ::== QUERY ( "requires" REQUIREMENTS )?
    QUERY ::== PROPOSITION | QUERY "&&" QUERY | QUERY "||" QUERY | "!" QUERY | "(" QUERY ")" | "+" | "-"
    PROPOSITION ::== HOLDSQUERY | ALWAYSQUERY | NECESSARILYQUERY
    HOLDSQUERY ::== "holds" "[" STATEFORMULA "]"
    ALWAYSQUERY ::== "always" "[" STATEFORMULA "]"
    NECESSARILYQUERY ::== "necessarily" "[" STATEFORMULA "]" "after" ACTIONS
    ACTIONS ::== ACTION ( ";" ACTION )*
    ACTION ::== "{" ACTIONNAME ("," ACTIONNAME)* "}"
    REQUIREMENTS ::== REQUIREMENT ("," REQUIREMENT)*
    REQUIREMENT ::== (VARIABLENAME "<>" VARIABLENAME | VARIABLENAME "<>" CONSTANTNAME)*

    where STATEFORMULA is an unquantified first-order formula without functors,
    and VARIABLENAME, CONSTANTNAME are sequences of symbols
    from {a,...,z,A,...,Z,0,...,9} with a letter at the beginning.
    Author:
    Sebastian Homann, Tim Janus (change constant LogicalSymbols to dynamic)
    • Method Summary

      Modifier and Type Method Description
      private void consumeToken​(java.util.Stack<java.lang.Object> stack, int c)
      This method reads one token from the given reader and appropriately constructs a propositional formula from the stream.
      private FolAction parseAction​(java.util.List<java.lang.Object> l)
      Parses a list of actionnames or a list of actions.
      private SActionQuery parseActionFormula​(java.util.Stack<java.lang.Object> stack)
      Parses a simple formula as a list of string tokens or formulas into an action query.
      private FolAtom parseActionName​(java.lang.String s)  
      private PlFormula parseAtomic​(java.util.List<java.lang.Object> l)
      Parses a simple formula as a list of String tokens or formulas into a propositional formula.
      SActionQuerySet parseBeliefBase​(java.io.Reader reader)
      Parses the given reader into a belief base of the given type.
      private PlFormula parseConjunction​(java.util.List<java.lang.Object> l)
      Parses a simple formula as a list of String tokens or formulas into a propositional formula.
      private PlFormula parseDisjunction​(java.util.List<java.lang.Object> l)
      Parses a simple formula as a list of String tokens or formulas into a propositional formula.
      SActionQuery parseFormula​(java.io.Reader reader)
      Parses the given reader into a formula of the given type.
      private PlFormula parseNegation​(java.util.List<java.lang.Object> l)
      Parses a simple formula as a list of String tokens or formulas into a propositional formula.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ActionQueryParser

        public ActionQueryParser​(ActionSignature signature)
    • Method Detail

      • consumeToken

        private void consumeToken​(java.util.Stack<java.lang.Object> stack,
                                  int c)
                           throws ParserException
        This method reads one token from the given reader and appropriately constructs a propositional formula from the stream.
        Parameters:
        stack - a stack used for monitoring the read items.
        c - a token from a stream.
        Throws:
        ParserException - in case of parser errors.
      • parseAction

        private FolAction parseAction​(java.util.List<java.lang.Object> l)
                               throws ParserException,
                                      java.io.IOException
        Parses a list of actionnames or a list of actions. Actions are strings of the form ACTIONNAME ("," ACTIONNAME)* into an action.
        Parameters:
        l - a list of action names
        Returns:
        an Action.
        Throws:
        ParserException - if parsing fails
        java.io.IOException - if IO fails
      • parseActionFormula

        private SActionQuery parseActionFormula​(java.util.Stack<java.lang.Object> stack)
                                         throws ParserException
        Parses a simple formula as a list of string tokens or formulas into an action query. This method expects a list of requirements at the end of the list.
        Parameters:
        stack - a stack of objects, either String tokens, objects of type PropositionalFormula or a list of requirements
        Returns:
        an action query
        Throws:
        ParserException - if parsing fails
      • parseDisjunction

        private PlFormula parseDisjunction​(java.util.List<java.lang.Object> l)
                                    throws ParserException
        Parses a simple formula as a list of String tokens or formulas into a propositional formula. This method expects no parentheses in the list and as such treats the formula as a disjunction.
        Parameters:
        l - a list objects, either String tokens or objects of type PropositionalFormula.
        Returns:
        a propositional formula.
        Throws:
        ParserException - if the list could not be parsed.
      • parseConjunction

        private PlFormula parseConjunction​(java.util.List<java.lang.Object> l)
                                    throws ParserException
        Parses a simple formula as a list of String tokens or formulas into a propositional formula. This method expects no parentheses and no disjunctions in the list and as such treats the formula as a conjunction.
        Parameters:
        l - a list objects, either String tokens or objects of type PropositionalFormula.
        Returns:
        a propositional formula.
        Throws:
        ParserException - if the list could not be parsed.
      • parseNegation

        private PlFormula parseNegation​(java.util.List<java.lang.Object> l)
                                 throws ParserException
        Parses a simple formula as a list of String tokens or formulas into a propositional formula. This method expects no parentheses, no disjunctions, and no conjunctions in the list and as such treats the formula as a negation.
        Parameters:
        l - a list objects, either String tokens or objects of type PropositionalFormula.
        Returns:
        a propositional formula.
        Throws:
        ParserException - if the list could not be parsed.
      • parseAtomic

        private PlFormula parseAtomic​(java.util.List<java.lang.Object> l)
                               throws ParserException
        Parses a simple formula as a list of String tokens or formulas into a propositional formula. This method expects no parentheses, no disjunctions, no conjunctions, and no negation in the list and as such treats the formula as an atomic construct, either a contradiction, a tautology, or a proposition.
        Parameters:
        l - a list objects, either String tokens or objects of type PropositionalFormula.
        Returns:
        a propositional formula.
        Throws:
        ParserException - if parsing fails