src/adfa/action.h \
src/adfa/adfa.h \
src/cfg/cfg.h \
+ src/dfa/closure_leftmost.h \
src/dfa/closure_posix.h \
src/dfa/determinization.h \
src/dfa/dfa.h \
src/cfg/rename.cc \
src/cfg/varalloc.cc \
src/dfa/closure.cc \
- src/dfa/closure_leftmost.cc \
src/dfa/dead_rules.cc \
src/dfa/determinization.cc \
src/dfa/fallback_tags.cc \
src/adfa/action.h \
src/adfa/adfa.h \
src/cfg/cfg.h \
+ src/dfa/closure_leftmost.h \
src/dfa/closure_posix.h \
src/dfa/determinization.h \
src/dfa/dfa.h \
src/cfg/rename.cc \
src/cfg/varalloc.cc \
src/dfa/closure.cc \
- src/dfa/closure_leftmost.cc \
src/debug/dump_adfa.cc \
src/debug/dump_cfg.cc \
src/debug/dump_dfa.cc \
#include "lib/regex_impl.h"
#include "src/options/opt.h"
#include "src/debug/debug.h"
+#include "src/dfa/closure_leftmost.h"
#include "src/dfa/determinization.h"
#include "src/nfa/nfa.h"
namespace libre2c {
static void reach_on_symbol(lsimctx_t &, uint32_t);
-static void closure_leftmost(lsimctx_t &);
static void update_offsets(lsimctx_t &ctx, const conf_t &c);
int regexec_nfa_leftmost(const regex_t *preg, const char *string
// root state can be non-core, so we pass zero as origin to avoid checks
const conf_t c0(ctx.nfa.root, 0, HROOT);
ctx.reach.push_back(c0);
- closure_leftmost(ctx);
+ closure_leftmost_dfs(ctx);
for (;;) {
const uint32_t sym = static_cast<uint8_t>(*ctx.cursor++);
if (ctx.state.empty() || sym == 0) break;
reach_on_symbol(ctx, sym);
++ctx.step;
- closure_leftmost(ctx);
+ closure_leftmost_dfs(ctx);
}
for (cconfiter_t i = ctx.state.begin(), e = ctx.state.end(); i != e; ++i) {
ctx.history.init();
}
-void closure_leftmost(lsimctx_t &ctx)
-{
- confset_t &state = ctx.state, &wl = ctx.reach;
- state.clear();
- for (; !wl.empty(); ) {
-
- const conf_t &x = wl.back();
- nfa_state_t *n = x.state;
- const uint32_t o = x.origin;
- const int32_t h = x.thist;
- wl.pop_back();
-
- if (n->clos != NOCLOS) continue;
-
- n->clos = 0;
- state.push_back(x);
-
- switch (n->type) {
- case nfa_state_t::NIL:
- wl.push_back(conf_t(n->nil.out, o, h));
- break;
- case nfa_state_t::ALT:
- wl.push_back(conf_t(n->alt.out2, o, h));
- wl.push_back(conf_t(n->alt.out1, o, h));
- break;
- case nfa_state_t::TAG:
- wl.push_back(conf_t(n->tag.out, o, ctx.history.link(ctx, x)));
- break;
- default:
- break;
- }
- }
-}
-
void update_offsets(lsimctx_t &ctx, const conf_t &c)
{
const size_t nsub = ctx.nsub;
#include "lib/regex_impl.h"
#include "src/options/opt.h"
#include "src/debug/debug.h"
+#include "src/dfa/closure_leftmost.h"
#include "src/dfa/determinization.h"
#include "src/nfa/nfa.h"
namespace re2c {
namespace libre2c {
-static void reach_on_symbol(lzsimctx_t &, uint32_t);
-static void closure_leftmost(lzsimctx_t &);
+static void make_step(lzsimctx_t &, uint32_t);
+static void make_final_step(lzsimctx_t &ctx);
int regexec_nfa_leftmost_trie(const regex_t *preg, const char *string
, size_t nmatch, regmatch_t pmatch[], int)
nfa_state_t *s0 = ctx.nfa.root;
const conf_t c0(s0, s0->coreid, HROOT);
ctx.reach.push_back(c0);
- closure_leftmost(ctx);
-
+ closure_leftmost_dfs(ctx);
for (;;) {
const uint32_t sym = static_cast<uint8_t>(*ctx.cursor++);
if (ctx.state.empty() || sym == 0) break;
- reach_on_symbol(ctx, sym);
- ++ctx.step;
- closure_leftmost(ctx);
- }
-
- const confset_t &state = ctx.state;
- cconfiter_t b = state.begin(), e = state.end(), i;
- for (i = b; i != e; ++i) {
- i->state->clos = NOCLOS;
+ make_step(ctx, sym);
+ closure_leftmost_dfs(ctx);
}
+ make_final_step(ctx);
return finalize(ctx, string, nmatch, pmatch);
}
-void reach_on_symbol(lzsimctx_t &ctx, uint32_t sym)
+void make_step(lzsimctx_t &ctx, uint32_t sym)
{
const confset_t &state = ctx.state;
confset_t &reach = ctx.reach;
}
}
}
+ else if (s->type == nfa_state_t::FIN) {
+ ctx.marker = ctx.cursor;
+ ctx.hidx = i->thist;
+ ctx.rule = 0;
+ }
}
+
+ ++ctx.step;
}
-void closure_leftmost(lzsimctx_t &ctx)
+void make_final_step(lzsimctx_t &ctx)
{
- confset_t &state = ctx.state, &wl = ctx.reach;
- state.clear();
- for (; !wl.empty(); ) {
-
- const conf_t &x = wl.back();
- nfa_state_t *n = x.state;
- const uint32_t o = x.origin;
- const int32_t h = x.thist;
- wl.pop_back();
-
- if (n->clos != NOCLOS) continue;
-
- n->clos = 0;
- state.push_back(x);
-
- switch (n->type) {
- case nfa_state_t::NIL:
- wl.push_back(conf_t(n->nil.out, o, h));
- break;
- case nfa_state_t::ALT:
- wl.push_back(conf_t(n->alt.out2, o, h));
- wl.push_back(conf_t(n->alt.out1, o, h));
- break;
- case nfa_state_t::TAG:
- wl.push_back(conf_t(n->tag.out, o, ctx.history.link(ctx, x)));
- break;
- case nfa_state_t::RAN:
- break;
- case nfa_state_t::FIN:
- ctx.marker = ctx.cursor + 1;
- ctx.hidx = x.thist;
- ctx.rule = 0;
- break;
+ for (confiter_t i = ctx.state.begin(), e = ctx.state.end(); i != e; ++i) {
+ nfa_state_t *s = i->state;
+
+ s->clos = NOCLOS;
+ DASSERT(s->active == 0);
+
+ if (s->type == nfa_state_t::FIN) {
+ ctx.marker = ctx.cursor;
+ ctx.hidx = i->thist;
+ ctx.rule = 0;
}
}
}
-#include <queue>
-#include <stdio.h>
-
#include "lib/lex.h"
#include "lib/regex.h"
#include "lib/regex_impl.h"
#include "src/options/opt.h"
#include "src/dfa/determinization.h"
#include "src/dfa/dfa.h"
+#include "src/dfa/closure_leftmost.h"
#include "src/dfa/closure_posix.h"
#include "src/dfa/posix_precedence.h"
#include "src/dfa/tcmd.h"
+++ /dev/null
-#include "src/dfa/determinization.h"
-#include "src/nfa/nfa.h"
-
-
-namespace re2c
-{
-
-void closure_leftmost(ldetctx_t &ctx)
-{
- closure_t &done = ctx.state, &todo = ctx.reach;
- done.clear();
-
- // DFS; linear complexity
- for (; !todo.empty(); ) {
- const clos_t &x = todo.back();
- nfa_state_t *n = x.state;
- todo.pop_back();
-
- if (n->clos != NOCLOS) continue;
-
- n->clos = static_cast<uint32_t>(done.size());
- done.push_back(x);
-
- switch (n->type) {
- case nfa_state_t::NIL:
- todo.push_back(clos_t(x, n->nil.out));
- break;
- case nfa_state_t::ALT:
- todo.push_back(clos_t(x, n->alt.out2));
- todo.push_back(clos_t(x, n->alt.out1));
- break;
- case nfa_state_t::TAG:
- todo.push_back(clos_t(x, n->tag.out, ctx.history.link(ctx, x)));
- break;
- default:
- break;
- }
- }
-
- // reset associated closure items
- // (do this before removing any states from closure)
- for (clositer_t i = done.begin(); i != done.end(); ++i) {
- i->state->clos = NOCLOS;
- }
-}
-
-} // namespace re2c
#include "src/util/slab_allocator.h"
-namespace re2c
-{
+namespace re2c {
// fwd
struct opt_t;
template<typename ctx_t> void tagged_epsilon_closure(ctx_t &ctx);
template<typename ctx_t> void find_state(ctx_t &ctx);
-void closure_leftmost(ldetctx_t &);
inline bool cmp_gtop_t::operator() (const nfa_state_t *x, const nfa_state_t *y) const
{