summaryrefslogtreecommitdiff
path: root/grammar.rb
diff options
context:
space:
mode:
Diffstat (limited to 'grammar.rb')
-rw-r--r--grammar.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/grammar.rb b/grammar.rb
index 3ee8105..8a08cc1 100644
--- a/grammar.rb
+++ b/grammar.rb
@@ -69,11 +69,13 @@ class Grammar
def initialize fn
@rules = []
+ @glue_rules = []
ReadFile.readlines_strip(fn).each_with_index { |s,j|
- #STDERR.write '.'
- #puts "\n" if j%100==0&&j>0
+ STDERR.write '.'
+ STDERR.write "\n" if (j+1)%80==0
@rules << Rule.from_s(s)
}
+ STDERR.write "\n"
end
def to_s
@@ -83,9 +85,12 @@ class Grammar
end
def add_glue_rules
+ # see https://github.com/jweese/thrax/wiki/Glue-grammar
@rules.map { |r| r.lhs.symbol }.reject { |s| s=='S' }.uniq.each { |s|
@rules << Rule.new(NT.new('S'), [NT.new(s)])
+ @glue_rules << @rules.last
@rules << Rule.new(NT.new('S'), [NT.new('S'), NT.new('X')])
+ @glue_rules << @rules.last
}
end