From c8b4abf55672fb27eca97e921ca0e12057dcc0cf Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Thu, 8 May 2014 17:56:31 +0200 Subject: correct, but still slow --- grammar.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'grammar.rb') 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 -- cgit v1.2.3