From f24adbe3051bc4f7fcf438ed6c8983da6ac610d0 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 9 Sep 2015 08:44:36 -0400 Subject: [PATCH] nitcc: collect items with conflict (now that there is always a resolution attempt) Signed-off-by: Jean Privat --- contrib/nitcc/src/grammar.nit | 8 ++++++++ contrib/nitcc/src/nitcc.nit | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/nitcc/src/grammar.nit b/contrib/nitcc/src/grammar.nit index da31377..040c6da 100644 --- a/contrib/nitcc/src/grammar.nit +++ b/contrib/nitcc/src/grammar.nit @@ -1009,6 +1009,7 @@ class LRState if a.length > 1 then print "REDUCE/REDUCE Conflict on state {self.number} {self.name} for token {t}:" for i in a do print "\treduce: {i}" + conflicting_items.add_all a end if guarded_shift.has_key(t) then var ri = a.first @@ -1048,6 +1049,8 @@ class LRState print "\treduce: {ri}" for i in guarded_shift[t] do print "\tshift: {i}" removed_reduces.add t + conflicting_items.add_all a + conflicting_items.add_all guarded_shift[t] end end end @@ -1057,6 +1060,11 @@ class LRState end end + # Items within a reduce/reduce or a shift/reduce conflict. + # + # Is computed by `analysis` + var conflicting_items = new ArraySet[Item] + # Return `i` and all other items of the state that expands, directly or indirectly, to `i` fun back_expand(i: Item): Set[Item] do diff --git a/contrib/nitcc/src/nitcc.nit b/contrib/nitcc/src/nitcc.nit index a499217..7e380e1 100644 --- a/contrib/nitcc/src/nitcc.nit +++ b/contrib/nitcc/src/nitcc.nit @@ -72,8 +72,8 @@ end var lr = gram.lr0 var conflitcs = new ArraySet[Production] -for s in lr.states do for t, a in s.guarded_reduce do if a.length > 1 or s.guarded_shift.has_key(t) then - for i in a do conflitcs.add(i.alt.prod) +for s in lr.states do + for i in s.conflicting_items do conflitcs.add(i.alt.prod) end if not conflitcs.is_empty then -- 1.7.9.5