From 07e02b2386b1e21141f23118d0a00a2ab1e8dd3d Mon Sep 17 00:00:00 2001 From: Robin Jadoul Date: Mon, 2 Jan 2017 11:45:50 +0100 Subject: [PATCH] More C++ LR templates --- templates/c++/lr.cpp | 13 +++++++++++++ templates/c++/lr.h | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 templates/c++/lr.cpp 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,