Class DetectAmbiguousVisitor
- java.lang.Object
-
- net.emustudio.edigen.Visitor
-
- net.emustudio.edigen.passes.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 ambiguityPath 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
Rule Mask (111) Pattern (101) Mask (101) Pattern (101)Variant ambiguity Variant ambiguity means that one pattern has more than one child variant.
-
-
Constructor Summary
Constructors Constructor Description DetectAmbiguousVisitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidvisit(Mask mask)Adds the mask to the list of child masks.voidvisit(Pattern pattern)Detects possible ambiguity under the pattern node and traverses the children.voidvisit(Rule rule)Detects possible ambiguity under the rule node and traverses the children.
-
-
-
Method Detail
-
visit
public void visit(Rule rule) throws SemanticException
Detects possible ambiguity under the rule node and traverses the children.- Overrides:
visitin classVisitor- 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.
-
visit
public void visit(Pattern pattern) throws SemanticException
Detects possible ambiguity under the pattern node and traverses the children.- Overrides:
visitin classVisitor- Parameters:
pattern- the pattern node- Throws:
SemanticException- when an ambiguity is detected
-
-