Add EOF token to Start rule patterns

This commit is contained in:
Josh Holtrop 2021-08-29 11:48:49 -04:00
parent 6026bf1514
commit ceb7e9ee32
2 changed files with 7 additions and 3 deletions

View File

@ -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)

View File

@ -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