summaryrefslogtreecommitdiff
path: root/grammar.rb
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-05-05 20:26:57 +0200
committerPatrick Simianer <p@simianer.de>2014-05-05 20:26:57 +0200
commit9a48eeb5afbbece30b4be425c9f24649307d3ed6 (patch)
tree859beee46c0e5e24e7391d9e5b33b728974f275e /grammar.rb
parentc7ac73b498ccd72a1af2b99ecdb71c730658479b (diff)
refactoring
Diffstat (limited to 'grammar.rb')
-rw-r--r--grammar.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/grammar.rb b/grammar.rb
index ac97fbd..b516912 100644
--- a/grammar.rb
+++ b/grammar.rb
@@ -14,22 +14,22 @@ class Terminal
end
class NonTerminal
- attr_accessor :sym, :n
+ attr_accessor :sym, :idx
- def initialize s, n=1
- @sym = s
- @n = n
+ def initialize sym, idx=0
+ @sym = sym
+ @idx = idx
end
def to_s
- "NT<#{sym}>"
+ "NT<#{sym},#{idx}>"
end
end
class Span
attr_accessor :left, :right
- def initialize left=-1, right=-1
+ def initialize left=nil, right=nil
@left = left
@right = right
end
@@ -38,10 +38,9 @@ end
class Rule
attr_accessor :lhs, :rhs, :span
- def initialize lhs=nil, rhs=nil, span=Span.new
+ def initialize lhs=nil, rhs=nil, span=nil
@lhs = ''
@rhs = []
- @span = span
end
def to_s
@@ -69,7 +68,7 @@ class Rule
def self.from_s s
r = self.new
r.from_s s
- return r
+ r
end
end
@@ -78,15 +77,14 @@ class Grammar
def initialize fn
@rules = []
- l = ReadFile.readlines_strip fn
- l.each { |i|
- @rules << Rule.from_s(i)
- }
+ a = ReadFile.readlines_strip fn
+ a.each { |s| @rules << Rule.from_s(s) }
end
def to_s
s = ''
@rules.each { |r| s += r.to_s+"\n" }
+ s
end
end