Skip to content

Commit

Permalink
Fix Bug: Support loop on a node with nullable variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Borjianamin98 authored and IYP-Programer-Yeah committed Feb 6, 2020
1 parent 29c5664 commit 1797178
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ir.ac.sbu</groupId>
<artifactId>PGen</artifactId>
<version>2.1</version>
<version>2.1.1</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ir/ac/sbu/parser/LLParserGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,15 @@ private Set<String> calculateFirstSet(Map<Integer, Set<String>> firstSets, Set<I
calculate first set
if there is an edge from N1 to N2 with token (or variable) C:
first{N1} += first{C} + (first{N2} | if C is a variable and C is nullable)
if C is nullable and N1 == N2 (C is a loop), then first{N1} += first{C}
*/
for (EdgeModel edgeModel : nodeModel.getAdjacent()) {
if (edgeModel.isGraph()) {
Set<String> firstSetOfGraph = calculateFirstSet(firstSets, visited,
variableGraph.get(edgeModel.getToken()).getStart());
firstOfCurrentNode.addAll(firstSetOfGraph);
if (nullableVariables.contains(edgeModel.getToken())) {
if (nullableVariables.contains(edgeModel.getToken()) &&
edgeModel.getEnd().getId() != nodeModel.getId()) {
Set<String> firstSetOfRestOfGraph = calculateFirstSet(firstSets, visited,
edgeModel.getEnd());
firstOfCurrentNode.addAll(firstSetOfRestOfGraph);
Expand Down

0 comments on commit 1797178

Please sign in to comment.