Start generating lexer states and transitions
This commit is contained in:
parent
5881f13380
commit
2122ca02fe
@ -10,4 +10,33 @@ class <%= classname %>
|
||||
TOKEN_<%= token.c_name %>,
|
||||
<% end %>
|
||||
}
|
||||
|
||||
private struct Transition
|
||||
{
|
||||
uint first;
|
||||
uint last;
|
||||
uint dest;
|
||||
}
|
||||
|
||||
private struct LexerState
|
||||
{
|
||||
Transition[] transitions;
|
||||
size_t accepts;
|
||||
}
|
||||
|
||||
private static const LexerState lexer_states[] = [
|
||||
<% lexer_dfa.enumerate.each do |state, index| %>
|
||||
LexerState([
|
||||
<% state.transitions.each do |transition| %>
|
||||
Transition(<%= transition.code_point_range.first %>, <%= transition.code_point_range.last %>, <%= lexer_dfa.enumerate[transition.destination] %>),
|
||||
<% end %>
|
||||
],
|
||||
<% if state.accepts %>
|
||||
<%= state.accepts.id %>,
|
||||
<% else %>
|
||||
cast(size_t)-1,
|
||||
<% end %>
|
||||
),
|
||||
<% end %>
|
||||
];
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ module Imbecile
|
||||
end
|
||||
|
||||
def enumerate
|
||||
@_enumerated ||=
|
||||
begin
|
||||
id = 0
|
||||
states = {}
|
||||
visit = lambda do |state|
|
||||
@ -53,6 +55,7 @@ module Imbecile
|
||||
visit[@start_state]
|
||||
states
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user