X-Git-Url: http://nitlanguage.org diff --git a/contrib/nitcc/src/grammar.nit b/contrib/nitcc/src/grammar.nit index e77f4e9..095072e 100644 --- a/contrib/nitcc/src/grammar.nit +++ b/contrib/nitcc/src/grammar.nit @@ -648,14 +648,12 @@ private class Generator add "\tredef fun start_state do return state_{states.first.cname}" add "end" - add "redef class Object" for s in states do - add "\tprivate fun state_{s.cname}: LRState{s.cname} do return once new LRState{s.cname}" + add "private fun state_{s.cname}: LRState{s.cname} do return once new LRState{s.cname}" end for p in gram.prods do - add "\tprivate fun goto_{p.cname}: Goto_{p.cname} do return once new Goto_{p.cname}" + add "private fun goto_{p.cname}: Goto_{p.cname} do return once new Goto_{p.cname}" end - add "end" add "redef class NToken" for s in states do @@ -997,11 +995,14 @@ 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}:" for i in a do print "\treduce: {i}" - else if guarded_shift.has_key(t) then + end + if guarded_shift.has_key(t) then var ri = a.first var confs = new Array[Item] var ress = new Array[String] @@ -1033,14 +1034,19 @@ 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}" for i in guarded_shift[t] do print "\tshift: {i}" + removed_reduces.add t end end end + for t in removed_reduces do + guarded_reduce.keys.remove(t) + t.reduces.remove(self) + end end # Return `i` and all other items of the state that expands, directly or indirectly, to `i`