More C++ LR templates

This commit is contained in:
Robin Jadoul 2017-01-02 11:45:50 +01:00
parent 06b1ef75e1
commit 07e02b2386
2 changed files with 15 additions and 2 deletions
templates/c++

13
templates/c++/lr.cpp Normal file
View File

@ -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}} };

View File

@ -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,