Class PlParser


  • public class PlParser
    extends Parser<PlBeliefSet,​PlFormula>
    This class implements a parser for propositional logic. The BNF for a propositional belief set is given by (starting symbol is FORMULASET)

    FORMULASET ::== FORMULA ( "\n" FORMULA )*
    FORMULA ::== PROPOSITION | "(" FORMULA ")" | FORMULA ">>" FORMULA | FORMULA "||" FORMULA | FORMULA "=>" FORMULA | FORMULA "<=>" FORMULA | "!" FORMULA | "+" | "-"

    PROPOSITION is a sequence of characters excluding |,&,!,(,),=,<,> and whitespace characters.
    Author:
    Matthias Thimm, Bastian Wolf
    • Constructor Summary

      Constructors 
      Constructor Description
      PlParser()  
    • 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 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.
      PlBeliefSet 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.
      private PlFormula parseEquivalence​(java.util.List<java.lang.Object> l)
      Parses a simple formula as a list of String tokens or formulas into a propositional formula.
      PlFormula parseFormula​(java.io.Reader reader)
      Parses the given reader into a formula of the given type.
      private PlFormula parseImplication​(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 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

      • PlParser

        public PlParser()
    • 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.
      • parseEquivalence

        private PlFormula parseEquivalence​(java.util.List<java.lang.Object> l)
        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 equivalence.
        Parameters:
        l - a list objects, either String tokens or objects of type PlFormula.
        Returns:
        a PlFormula.
        Throws:
        ParserException - if the list could not be parsed.
      • parseImplication

        private PlFormula parseImplication​(java.util.List<java.lang.Object> l)
        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 implication.
        Parameters:
        l - a list objects, either String tokens or objects of type PlFormula.
        Returns:
        a PlFormula.
        Throws:
        ParserException - if the list could not be parsed.
      • 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