Add FA#build_tables

This commit is contained in:
Josh Holtrop 2021-06-24 15:06:10 -04:00
parent 2122ca02fe
commit 98584ce07a
2 changed files with 22 additions and 1 deletions

View File

@ -15,7 +15,7 @@ class <%= classname %>
{ {
uint first; uint first;
uint last; uint last;
uint dest; uint destination;
} }
private struct LexerState private struct LexerState

View File

@ -57,6 +57,27 @@ module Imbecile
end end
end end
def build_tables
transition_table = []
state_table = []
states = enumerate
states.each do |state, id|
state_table << {
transition_table_index: transition_table.size,
n_transitions: state.transitions.size,
accepts: state.accepts ? state.accepts.id : 0xFFFFFFFF,
}
state.transitions.each do |transition|
transition_table << {
first: transition.code_point_range.first,
last: transition.code_point_range.last,
destination: states[transition.destination],
}
end
end
[transition_table, state_table]
end
end end
end end