# Generate a graphviz file of the automaton
fun to_dot(path: String)
do
- var f = new OFStream.open(path)
+ var f = new FileWriter.open(path)
f.write("digraph g \{\n")
f.write("rankdir=LR;\n")
f.write("node[shape=Mrecord,height=0];\n")
do
var gen = new Generator
gen.gen_to_nit(self, name)
- var f = new OFStream.open(filepath)
+ var f = new FileWriter.open(filepath)
for s in gen.out do
f.write(s)
f.write("\n")
var gram = autom.grammar
add "# Parser generated by nitcc for the grammar {name}"
+ add "module {name}_parser is no_warning(\"missing-doc\",\"old-init\")"
add "import nitcc_runtime"
add "class Parser_{name}"
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
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}:"
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}"
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`