diff --git a/templates/c++/lr.cpp b/templates/c++/lr.cpp new file mode 100644 index 0000000..388fb34 --- /dev/null +++ b/templates/c++/lr.cpp @@ -0,0 +1,13 @@ +#include "{{name}}.h" + +#define TABLE {{name}}___Table___{{name}} +#define REDUCE_COUNT {{name}}___Num_Reduces___{{name}} + +const std::uint64_t TABLE[{{num_states}}][{{num_symbols}}] = { + {{#states}} + { {{#actions}}({{name}}::{{action}} | {{data}} << 2),{{/actions}} + {{#gotos}}({{data}} << 2),{{/gotos}} }, + {{/states}} +}; + +const unsigned char REDUCE_COUNT[{{num_rules}}] = { {{#rules}}{{rhs_length}}{{/rules}} }; diff --git a/templates/c++/lr.h b/templates/c++/lr.h index 1b8871b..a05015d 100644 --- a/templates/c++/lr.h +++ b/templates/c++/lr.h @@ -60,8 +60,8 @@ class {{name}} { #define TABLE {{name}}___Table___{{name}} #define REDUCE_COUNT {{name}}___Num_Reduces___{{name}} // Not a static member because the table should not be replicated for different instantiations of the parser -extern const std::uint64_t TABLE[%(num_states)][%(num_symbols)]; -extern const unsigned char REDUCE_COUNT[%(num_rules)]; +extern const std::uint64_t TABLE[{{num_states}}][{{num_symbols}}]; +extern const unsigned char REDUCE_COUNT[{{num_rules}}]; enum Action { ERROR = 0,