else
res.append("{p.name} =\n")
end
- var last = p.alts.last
+ var last = null
+ if not p.alts.is_empty then p.alts.last
for a in p.alts do
res.append("\t\{{a.name}:\} {a.elems.join(" ")}")
if a.codes == null then a.make_codes
do
for p in self.prods do
for a in p.alts.to_a do
+ if a.phony then continue
var to_inline = false
for e in a.elems do
if e isa Production and prods.has(e) then to_inline = true
end
pool2.clear
for a2 in e.alts do
+ if a.phony then continue
if a2.codes == null then a2.make_codes
for x in pool do
var name = a.name + "_" + pool2.length.to_s
for p in prods do
if p.is_nullable then continue
for a in p.alts do
+ if a.phony then continue
var nullabl = true
for e in a.elems do
if e isa Token then
for p in prods do
var fs = p.firsts
for a in p.alts do
+ if a.phony then continue
var i = a.first_item
loop
var e = i.next
var changed = false
for p1 in prods do
for a in p1.alts do
+ if a.phony then continue
var p0: nullable Production = null
var i = a.first_item
loop
# Is self transformed to a other production for the AST
# FIXME: cleaup AST
- var spe: nullable Production writable = null
+ var spe: nullable Production = null is writable
# Is self contains only a single alternative (then no need for a abstract production class in the AST)
# FIXME cleanup AST
- var altone writable = false
+ var altone = false is writable
# The cname of the class in the AST
# FIXME: cleanup AST
do
var res = new Array[Item]
for a in alts do
+ if a.phony then continue
res.add a.first_item
end
return res
var prod: Production
# The name of the alternative
- var name: String writable
+ var name: String is writable
# The elements of the alternative
var elems: Array[Element]
end
# The code for the reduction
- var codes: nullable Array[Code] writable = null
+ var codes: nullable Array[Code] = null is writable
# Is the alternative transformed (ie not in the AST)
- var trans writable = false
+ var trans = false is writable
+
+ # Is the alternative unparsable? (ie not in the automaton)
+ var phony = false is writable
# Imitialize codes with the elements
fun make_codes
end
end
-redef class String
- # escape string used in labels for graphviz
- fun escape_to_dot: String
- do
- return escape_more_to_c("|\{\}")
- end
-end
-
private class Generator
var out = new Array[String]
fun add(s: String) do out.add(s)