43 lines
1.1 KiB
Plaintext
43 lines
1.1 KiB
Plaintext
<% if @grammar.modulename %>
|
|
module <%= @grammar.modulename %>;
|
|
|
|
<% end %>
|
|
class <%= classname %>
|
|
{
|
|
enum
|
|
{
|
|
<% @grammar.tokens.each_with_index do |token, index| %>
|
|
<% if token.name %>
|
|
TOKEN_<%= token.c_name %> = <%= index %>,
|
|
<% end %>
|
|
<% end %>
|
|
}
|
|
|
|
private struct Transition
|
|
{
|
|
uint first;
|
|
uint last;
|
|
uint destination;
|
|
}
|
|
|
|
private struct LexerState
|
|
{
|
|
uint transition_table_index;
|
|
uint n_transitions;
|
|
uint accepts;
|
|
}
|
|
|
|
<% transition_table, state_table = lexer_dfa.build_tables %>
|
|
private static const Transition transitions[] = [
|
|
<% transition_table.each do |transition_table_entry| %>
|
|
Transition(<%= transition_table_entry[:first] %>, <%= transition_table_entry[:last] %>, <%= transition_table_entry[:destination] %>),
|
|
<% end %>
|
|
];
|
|
|
|
private static const LexerState lexer_states[] = [
|
|
<% state_table.each do |state_table_entry| %>
|
|
LexerState(<%= state_table_entry[:transition_table_index] %>, <%= state_table_entry[:n_transitions] %>, <%= state_table_entry[:accepts] %>),
|
|
<% end %>
|
|
];
|
|
}
|