nitcc: remove S/R reduction after detection to avoid concurent iteration/mutation...
authorJean Privat <jean@pryen.org>
Wed, 9 Sep 2015 09:25:49 +0000 (05:25 -0400)
committerJean Privat <jean@pryen.org>
Wed, 9 Sep 2015 09:25:49 +0000 (05:25 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

contrib/nitcc/src/grammar.nit

index e05e447..fc10a98 100644 (file)
@@ -995,6 +995,8 @@ class LRState
                                abort
                        end
                end
+               # Token to remove as reduction guard to solve S/R conflicts
+               var removed_reduces = new Array[Token]
                for t, a in guarded_reduce do
                        if a.length > 1 then
                                print "REDUCE/REDUCE Conflict on state {self.number} {self.name} for token {t}:"
@@ -1031,7 +1033,7 @@ class LRState
                                        print "Automatic Dangling on state {self.number} {self.name} for token {t}:"
                                        print "\treduce: {ri}"
                                        for r in ress do print r
-                                       guarded_reduce.keys.remove(t)
+                                       removed_reduces.add t
                                else
                                        print "SHIFT/REDUCE Conflict on state {self.number} {self.name} for token {t}:"
                                        print "\treduce: {ri}"
@@ -1039,6 +1041,9 @@ class LRState
                                end
                        end
                end
+               for t in removed_reduces do
+                       guarded_reduce.keys.remove(t)
+               end
        end
 
        # Return `i` and all other items of the state that expands, directly or indirectly, to `i`