Don't require the user to specify the symbol type for a reduce rule
This commit is contained in:
parent
85d5142c60
commit
06b1ef75e1
|
@ -50,8 +50,8 @@ class {{name}} {
|
|||
* Apply a reduction (a grammar rule in reverse)
|
||||
*/
|
||||
{{#rules}}
|
||||
{{#name}}virtual Token reduce_{{name}}(std::deque<Token> subparts) = 0;{{/name}}
|
||||
{{^name}}virtual Token reduce_{{index}}(std::deque<Token> subparts) = 0;{{/name}}
|
||||
{{#name}}virtual Value reduce_{{name}}(std::deque<Token> subparts) = 0;{{/name}}
|
||||
{{^name}}virtual Value reduce_{{index}}(std::deque<Token> subparts) = 0;{{/name}}
|
||||
{{/rules}}
|
||||
|
||||
private:
|
||||
|
@ -97,7 +97,10 @@ Value {{name}}::parse() {
|
|||
break;
|
||||
case REDUCE:
|
||||
{
|
||||
std::uint64_t rule = act >> 2;
|
||||
std::uint64_t tmp = act >> 2;
|
||||
Symbol symbol = tmp >> 31;
|
||||
std::uint32_t rule = tmp & ((1ull << 32) - 1);
|
||||
|
||||
std::deque<Token> dq;
|
||||
for (decltype(RECUDE_COUNT[rule]) i = 0; i < REDUCE_COUNT[rule]; i++) {
|
||||
dq.emplace_front(std::move(valueStack.top()));
|
||||
|
@ -108,8 +111,8 @@ Value {{name}}::parse() {
|
|||
switch (rule) {
|
||||
{{#rules}}
|
||||
case {{index}}:
|
||||
{{#name}}valueStack.emplace(reduce_{{name}}(std::move(dq))){{/name}}
|
||||
{{^name}}valueStack.emplace(reduce{{index}}(std::move(dq))){{/name}}
|
||||
{{#name}}valueStack.emplace({symbol, reduce_{{name}}(std::move(dq))}){{/name}}
|
||||
{{^name}}valueStack.emplace({symbol, reduce_{{index}}(std::move(dq))}){{/name}}
|
||||
break;
|
||||
{{/rules}}
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue