Class CParser

java.lang.Object
org.tweetyproject.commons.Parser<CActionDescription,Formula>
org.tweetyproject.action.description.parser.CParser

public class CParser extends Parser<CActionDescription,Formula>
This class implements a parser for an Action Description in the Action Description Language C from [Gelfond, Michael and Lifschitz, Vladimir: Action Languages. ETAI: Electronic Transactions on AI, 1998.] The BNF is given by: (starting symbol is DESC)

DESC ::== ":- signature" "\n" SIGNATURE "\n" ":- laws" "\n" LAWS
where SIGNATURE is parsed by CSignatureParser and LAWS is parsed by CLawParser.
Author:
Sebastian Homann
  • Constructor Details

    • CParser

      public CParser()
  • Method Details

    • parseBeliefBase

      public CActionDescription parseBeliefBase(Reader reader) throws IOException, ParserException
      Parses a belief base from the provided reader. The method reads from the reader and separates formulas by "\n". It follows a state-based approach where: - State 0 is for initialization - State 1 is for reading the signature - State 2 is for reading the lawbase
      Specified by:
      parseBeliefBase in class Parser<CActionDescription,Formula>
      Parameters:
      reader - the Reader object from which the belief base is read
      Returns:
      a CActionDescription object representing the parsed belief base
      Throws:
      IOException - if an I/O error occurs
      ParserException - if a parsing error occurs
    • parseFormula

      public Formula parseFormula(Reader reader) throws IOException, ParserException
      Parses a formula from the given reader.
      Specified by:
      parseFormula in class Parser<CActionDescription,Formula>
      Parameters:
      reader - the reader to read the formula from
      Returns:
      the parsed formula
      Throws:
      IOException - if an I/O error occurs while reading from the reader
      ParserException - if the formula cannot be parsed
    • parseFormula

      public Formula parseFormula(String formula) throws ParserException, IOException
      Parses the given formula string and returns the corresponding Formula object.
      Overrides:
      parseFormula in class Parser<CActionDescription,Formula>
      Parameters:
      formula - the formula string to be parsed
      Returns:
      the parsed Formula object
      Throws:
      ParserException - if there is an error during parsing
      IOException - if there is an error reading the formula string
    • setSignature

      public void setSignature(ActionSignature signature)
      Sets the action signature for this parser.
      Parameters:
      signature - the action signature to be set
    • getSignature

      public ActionSignature getSignature()
      Returns the signature of the action.
      Returns:
      the signature of the action