Class DetectAmbiguousVisitor


  • public class DetectAmbiguousVisitor
    extends Visitor

    A visitor which checks for ambiguous variants. This visitor is not a transformation; the tree is left unmodified. It must be applied after the grouping transformation.

    Ambiguity is dangerous, because it can cause unintended behavior not discovered until the generated decoder is run. There are two types of ambiguity: path ambiguity and variant ambiguity.

    Path ambiguity

    Path ambiguity means that for some rule and input, decoder is not able to decide which execution path to choose without reading more input, even if the deep contains solution. The reason is that Decoder is simple state machine which decides only based on the current state and input. It means that the current implementation of decoder doesn't support look-aheads.

    Effect of path ambiguity is that only the first found path would be executed by decoder, and all other ambiguous paths would be ignored forever. Therefore this smells of unintended behavior.

    Let N be a rule node or a Pattern node which is an indirect child of the rule. Then, two variants of the rule have ambiguous path if:

    • N has two direct children: masks M1 and M2
    • M1 has direct child pattern P1
    • M2 has direct child pattern P2
    • M1 & M2 & P1 = M1 & M2 & P2
    Example of path ambiguity:
         Rule
           Mask (111)
             Pattern (101)
           Mask (101)
             Pattern (101)
     
    Variant ambiguity Variant ambiguity means that one pattern has more than one child variant.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void visit​(Mask mask)
      Adds the mask to the list of child masks.
      void visit​(Pattern pattern)
      Detects possible ambiguity under the pattern node and traverses the children.
      void visit​(Rule rule)
      Detects possible ambiguity under the rule node and traverses the children.
      • Methods inherited from class java.lang.Object

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

      • DetectAmbiguousVisitor

        public DetectAmbiguousVisitor()
    • Method Detail

      • visit

        public void visit​(Rule rule)
                   throws SemanticException
        Detects possible ambiguity under the rule node and traverses the children.
        Overrides:
        visit in class Visitor
        Parameters:
        rule - the rule node
        Throws:
        SemanticException - when an ambiguity is detected
      • visit

        public void visit​(Mask mask)
        Adds the mask to the list of child masks.
        Overrides:
        visit in class Visitor
        Parameters:
        mask - the mask node
      • visit

        public void visit​(Pattern pattern)
                   throws SemanticException
        Detects possible ambiguity under the pattern node and traverses the children.
        Overrides:
        visit in class Visitor
        Parameters:
        pattern - the pattern node
        Throws:
        SemanticException - when an ambiguity is detected