Start generating lexer states and transitions

This commit is contained in:
josh committed 2021-06-23 23:15:02 -04:00
1 parent 5881f13380
commit 2122ca02fe
2 files changed
+32

No files matched your search

+29
View File
@@ -10,4 +10,33 @@ class <%= classname %>
TOKEN_<%= token.c_name %>, TOKEN_<%= token.c_name %>,
<% end %> <% 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 %>
];
} }
+3
View File
@@ -39,6 +39,8 @@ module Imbecile
end end
def enumerate def enumerate
@_enumerated ||=
begin
id = 0 id = 0
states = {} states = {}
visit = lambda do |state| visit = lambda do |state|
@@ -53,6 +55,7 @@ module Imbecile
visit[@start_state] visit[@start_state]
states states
end end
end
end end