Skip to content
Snippets Groups Projects
Commit 3a3408c8 authored by picomeg's avatar picomeg
Browse files

actually use param k to find lookahead (was hardcoded to 1)

parent 4a2f5887
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "contextfree.h" #include "contextfree.h"
#include "lr.h" #include "lr.h"
static const size_t DEFAULT_K = 1;
/* LALR-via-SLR grammar transformation */ /* LALR-via-SLR grammar transformation */
...@@ -275,6 +275,7 @@ HCFChoice *h_desugar_augmented(HAllocator *mm__, HParser *parser) ...@@ -275,6 +275,7 @@ HCFChoice *h_desugar_augmented(HAllocator *mm__, HParser *parser)
int h_lalr_compile(HAllocator* mm__, HParser* parser, const void* params) int h_lalr_compile(HAllocator* mm__, HParser* parser, const void* params)
{ {
size_t k = params? (uintptr_t)params : DEFAULT_K;
// generate (augmented) CFG from parser // generate (augmented) CFG from parser
// construct LR(0) DFA // construct LR(0) DFA
// build LR(0) table // build LR(0) table
...@@ -335,7 +336,7 @@ int h_lalr_compile(HAllocator* mm__, HParser* parser, const void* params) ...@@ -335,7 +336,7 @@ int h_lalr_compile(HAllocator* mm__, HParser* parser, const void* params)
if(match_any_production(table, eg, lhs, item->rhs, state)) { if(match_any_production(table, eg, lhs, item->rhs, state)) {
// the left-hand symbol's follow set is this production's // the left-hand symbol's follow set is this production's
// contribution to the lookahead // contribution to the lookahead
const HStringMap *fs = h_follow(1, eg->grammar, lhs); const HStringMap *fs = h_follow(k, eg->grammar, lhs);
assert(fs != NULL); assert(fs != NULL);
assert(fs->epsilon_branch == NULL); assert(fs->epsilon_branch == NULL);
// NB: there is a case where fs can be empty: when reducing by lhs // NB: there is a case where fs can be empty: when reducing by lhs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment