Skip to content
Snippets Groups Projects
Commit ffc8b55c authored by Sergio Pérez's avatar Sergio Pérez
Browse files

Removed Left Recursive Grammars in Summary Edges (Problem Benchmark 8)

parent fd6f61ee
No related branches found
No related tags found
No related merge requests found
......@@ -89,10 +89,14 @@ public class AsteriskConstraint extends EdgeConstraint
}
private boolean existsPreviousAsteriskConstraint(Constraints constraints){
for(Constraint c : constraints.getEdgeConstraints())
boolean previousAsterisk = false;
for(Constraint c : constraints.getEdgeConstraints()) {
if (c instanceof AsteriskConstraint)
return true;
return false;
previousAsterisk = true;
if (previousAsterisk && c instanceof GrammarConstraint)
previousAsterisk = false;
}
return previousAsterisk;
}
private Constraints popToAsteriskConstraint(Constraints constraints){
......
......@@ -139,7 +139,8 @@ public class SummaryEdgeGenerator extends EdgeGenerator
final Grammar grammar = this.edg.getGrammar();
final GrammarConstraint grammarConstraint = new GrammarConstraint(grammar, formalIn);
boolean isNewGrammarTerm = grammar.isNewGrammarTerm(grammarConstraint);
this.edg.addProduction(grammarConstraint, constraints);
if (!isLeftRecursiveGrammar(grammarConstraint, constraints))
this.edg.addProduction(grammarConstraint, constraints);
final List<Node> nodesToContinue = new LinkedList<>();
if (!isNewGrammarTerm)
......@@ -167,4 +168,14 @@ public class SummaryEdgeGenerator extends EdgeGenerator
workList.repend(id);
}
}
private boolean isLeftRecursiveGrammar(GrammarConstraint grammarConstraint, Constraints constraints)
{
if (constraints.getEdgeConstraints().isEmpty())
return false;
String grammarId = grammarConstraint.getRefNode().getId() + "";
String stackBottomTerm = constraints.getEdgeConstraints().firstElement().toString();
return grammarId.equals(stackBottomTerm);
}
}
\ No newline at end of file
......@@ -194,8 +194,7 @@ public class ValueEdgeGenerator {
{
final Node valueNode = this.last.getChild(listComprehensionNode, Node.Type.Value);
final Node value = this.last.getChild(valueNode, Node.Type.Value);
this.last.addEdge(valueNode, listComprehensionNode, Edge.Type.Value, negativeConstraint);
this.last.addEdge(value, valueNode, Edge.Type.Value, EmptyConstraint.getConstraint());
this.last.addEdge(value, listComprehensionNode, Edge.Type.Value, negativeConstraint);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment