summaryrefslogtreecommitdiff
path: root/grammar.rb
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-05-08 17:56:31 +0200
committerPatrick Simianer <p@simianer.de>2014-05-08 17:56:31 +0200
commitc8b4abf55672fb27eca97e921ca0e12057dcc0cf (patch)
treef29553541df4d63e45246f1f3415070dfbd2aa59 /grammar.rb
parent4400add706c01ebf1460701c651d66bbf592cfa5 (diff)
correct, but still slow
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