Class CLawParser


  • public class CLawParser
    extends Parser<CActionDescription,​Formula>
    This class implements a parser for causal laws in C. The BNF of such rules is given by: (starting symbol is DESC)

    DESC ::== LAW ("\n" LAW)*
    LAW ::== STATICLAW | DYNAMICLAW
    STATICLAW ::== "caused" FOLFORMULA ("if" FOLFORMULA)? ("requires" REQUIREMENTS)?
    DYNAMICLAW ::== "caused" FOLFORMULA ("if" FOLFORMULA)? "after" FOLFORMULA ("requires" REQUIREMENTS)?
    REQUIREMENTS ::== REQUIREMENT ("," REQUIREMENT)*
    REQUIREMENT ::== (VARIABLENAME "<>" VARIABLENAME | VARIABLENAME "<>" CONSTANTNAME)*
    where FOLFORMULA 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
    • Constructor Summary

      Constructors 
      Constructor Description
      CLawParser​(ActionSignature signature)
      This parser needs a valid action signature to parse causal laws.
    • Method Summary

      Modifier and Type Method Description
      protected java.util.Set<java.lang.String> containedKeywords​(java.lang.String s)
      Returns the set of forbidden keywords, that are contained in a string.
      private Formula parseAlwaysFormula​(java.lang.String s, java.lang.String reqString)
      Parses a string containing a single causal law of the form always A which is converted to caused - if !A
      CActionDescription parseBeliefBase​(java.io.Reader reader)
      Parses the given reader into a belief base of the given type.
      private Formula parseCausedFormula​(java.lang.String s, java.lang.String reqString)
      Parses a string containing a single causal law of the form caused A (if B)? (after C)?
      private Formula parseCausesFormula​(java.lang.String s, java.lang.String reqString)
      Parses a string containing a single causal law of the form A causes B if C which is converted to caused B if + after A && C
      private Formula parseDefaultFormula​(java.lang.String s, java.lang.String reqString)
      Parses a string containing a single causal law of the form default A (if B)? which is converted to the causal law caused A if A && B
      protected FolFormula parseFolFormula​(java.lang.String s)
      Parses a FolFormula from a string using the FolParser class
      Formula parseFormula​(java.io.Reader reader)
      Parses the given reader into a formula of the given type.
      Formula parseFormula​(java.lang.String s)
      Parses the given text into a formula of the given type.
      private Formula parseInertialFormula​(java.lang.String s, java.lang.String reqString)
      Parses a string containing a single causal law of the form inertial A which is converted to the causal law caused A if A after A
      private Formula parseMayCauseFormula​(java.lang.String s, java.lang.String reqString)
      Parses a string containing a single causal law of the form A may cause B if C which is converted to caused B if B after A && C
      private Formula parseNonexecutableFormula​(java.lang.String s, java.lang.String reqString)
      Parses a string containing a single causal law of the form nonexecutable A if B which is converted to caused - after A && B
      • Methods inherited from class java.lang.Object

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

      • CLawParser

        public CLawParser​(ActionSignature signature)
        This parser needs a valid action signature to parse causal laws.
        Parameters:
        signature - some signature
    • Method Detail

      • parseFormula

        public Formula parseFormula​(java.io.Reader reader)
                             throws java.io.IOException,
                                    ParserException
        Description copied from class: Parser
        Parses the given reader into a formula of the given type.
        Specified by:
        parseFormula in class Parser<CActionDescription,​Formula>
        Parameters:
        reader - a reader
        Returns:
        a formula
        Throws:
        java.io.IOException - if some IO issue occurred.
        ParserException - some parsing exceptions may be added here.
      • parseFolFormula

        protected FolFormula parseFolFormula​(java.lang.String s)
                                      throws ParserException,
                                             java.io.IOException
        Parses a FolFormula from a string using the FolParser class
        Parameters:
        s - a string
        Returns:
        A first order formula
        Throws:
        ParserException - if parsing fails
        java.io.IOException - if an IO issue occurs.
      • parseFormula

        public Formula parseFormula​(java.lang.String s)
                             throws ParserException,
                                    java.io.IOException
        Description copied from class: Parser
        Parses the given text into a formula of the given type.
        Overrides:
        parseFormula in class Parser<CActionDescription,​Formula>
        Parameters:
        s - a string
        Returns:
        a formula
        Throws:
        ParserException - some parsing exceptions may be added here.
        java.io.IOException - if some IO issue occurred.
      • parseCausedFormula

        private Formula parseCausedFormula​(java.lang.String s,
                                           java.lang.String reqString)
                                    throws ParserException,
                                           java.io.IOException
        Parses a string containing a single causal law of the form caused A (if B)? (after C)?
        Parameters:
        s - a string containing a single causal law.
        reqString - the grounding requirements of this law.
        Returns:
        the corresponding causal law
        Throws:
        ParserException - if parsing failes
        java.io.IOException - if io failes
      • parseInertialFormula

        private Formula parseInertialFormula​(java.lang.String s,
                                             java.lang.String reqString)
                                      throws ParserException,
                                             java.io.IOException
        Parses a string containing a single causal law of the form inertial A which is converted to the causal law caused A if A after A
        Parameters:
        s - a string containing a single inertial law.
        reqString - the grounding requirements of this law.
        Returns:
        the corresponding causal law
        Throws:
        ParserException - if parsing failes
        java.io.IOException - if io failes
      • parseDefaultFormula

        private Formula parseDefaultFormula​(java.lang.String s,
                                            java.lang.String reqString)
                                     throws ParserException,
                                            java.io.IOException
        Parses a string containing a single causal law of the form default A (if B)? which is converted to the causal law caused A if A && B
        Parameters:
        s - a string containing a single causal law.
        reqString - the grounding requirements of this law.
        Returns:
        the corresponding causal law
        Throws:
        ParserException - if parsing failes
        java.io.IOException - if io failes
      • parseCausesFormula

        private Formula parseCausesFormula​(java.lang.String s,
                                           java.lang.String reqString)
                                    throws ParserException,
                                           java.io.IOException
        Parses a string containing a single causal law of the form A causes B if C which is converted to caused B if + after A && C
        Parameters:
        s - a string containing a single causal law.
        reqString - the grounding requirements of this law.
        Returns:
        the corresponding causal law
        Throws:
        ParserException - if parsing failes
        java.io.IOException - if io failes
      • parseAlwaysFormula

        private Formula parseAlwaysFormula​(java.lang.String s,
                                           java.lang.String reqString)
                                    throws ParserException,
                                           java.io.IOException
        Parses a string containing a single causal law of the form always A which is converted to caused - if !A
        Parameters:
        s - a string containing a single causal law.
        reqString - the grounding requirements of this law.
        Returns:
        the corresponding causal law
        Throws:
        ParserException - if parsing failes
        java.io.IOException - if io failes
      • parseNonexecutableFormula

        private Formula parseNonexecutableFormula​(java.lang.String s,
                                                  java.lang.String reqString)
                                           throws ParserException,
                                                  java.io.IOException
        Parses a string containing a single causal law of the form nonexecutable A if B which is converted to caused - after A && B
        Parameters:
        s - a string containing a single causal law.
        reqString - the grounding requirements of this law.
        Returns:
        the corresponding causal law
        Throws:
        ParserException - if parsing failes
        java.io.IOException - if io failes
      • parseMayCauseFormula

        private Formula parseMayCauseFormula​(java.lang.String s,
                                             java.lang.String reqString)
                                      throws ParserException,
                                             java.io.IOException
        Parses a string containing a single causal law of the form A may cause B if C which is converted to caused B if B after A && C
        Parameters:
        s - a string containing a single causal law.
        reqString - the grounding requirements of this law.
        Returns:
        the corresponding causal law
        Throws:
        ParserException - if parsing failes
        java.io.IOException - if io failes
      • containedKeywords

        protected java.util.Set<java.lang.String> containedKeywords​(java.lang.String s)
        Returns the set of forbidden keywords, that are contained in a string. This is used for error recognition in input strings.
        Parameters:
        s - some string
        Returns:
        the set of forbidden keywords