diff --git a/lib/imbecile/parser.rb b/lib/imbecile/parser.rb index 2d3c90d..107c3f9 100644 --- a/lib/imbecile/parser.rb +++ b/lib/imbecile/parser.rb @@ -3,9 +3,11 @@ class Imbecile class Parser def initialize(tokens, rules) + token_eof = Token.new("$", nil, TOKEN_EOF) @item_sets = [] item_sets_set = Set.new start_items = rules["Start"].patterns.map do |pattern| + pattern.components << token_eof Item.new(pattern, 0) end start_item_set = ItemSet.new(start_items) diff --git a/lib/imbecile/token.rb b/lib/imbecile/token.rb index e4283e7..b7607c4 100644 --- a/lib/imbecile/token.rb +++ b/lib/imbecile/token.rb @@ -22,9 +22,11 @@ class Imbecile @name = name @pattern = pattern @id = id - regex = Regex.new(pattern) - regex.nfa.end_state.accepts = self - @nfa = regex.nfa + unless pattern.nil? + regex = Regex.new(pattern) + regex.nfa.end_state.accepts = self + @nfa = regex.nfa + end end def c_name