src
nfa.cc
Go to the documentation of this file.
1 #include "src/ir/nfa/nfa.h"
2 #include "src/ir/regexp/regexp.h"
9 
10 namespace re2c {
11 
13  : max_size(re->calc_size())
14  , size(0)
15  , states(new nfa_state_t[max_size])
16  , root(re->compile(*this, NULL))
17 {}
18 
20 {
21  delete[] states;
22 }
23 
25 {
26  nfa_state_t *s = &nfa.states[nfa.size++];
27  s->alt(exp1->compile(nfa, t),
28  exp2->compile(nfa, t));
29  return s;
30 }
31 
33 {
34  nfa_state_t *s2 = exp2->compile(nfa, t);
35  nfa_state_t *s1 = exp1->compile(nfa, s2);
36  return s1;
37 }
38 
40 {
41  nfa_state_t *s = &nfa.states[nfa.size++];
42  s->alt(t, exp->compile(nfa, s));
43  return s;
44 }
45 
47 {
48  nfa_state_t *s = &nfa.states[nfa.size++];
49  s->ran(t, match);
50  return s;
51 }
52 
54 {
55  return t;
56 }
57 
59 {
60  nfa_state_t *s3 = &nfa.states[nfa.size++];
61  s3->fin(this);
62  if (ctx->calc_size() > 0)
63  {
64  nfa_state_t *s2 = &nfa.states[nfa.size++];
65  s2->ctx(ctx->compile(nfa, s3));
66  s3 = s2;
67  }
68  nfa_state_t *s1 = exp->compile(nfa, s3);
69  return s1;
70 }
71 
72 } // namespace re2c
nfa_t(RegExp *re)
Definition: nfa.cc:12
nfa_state_t * compile(nfa_t &nfa, nfa_state_t *n)
Definition: nfa.cc:46
Range * match
Definition: regexp_match.h:13
smart_ptr< DFA > compile(Spec &spec, Output &output, const std::string &cond, uint32_t cunits)
Definition: compile.cc:29
nfa_state_t * compile(nfa_t &nfa, nfa_state_t *n)
Definition: nfa.cc:53
nfa_state_t * compile(nfa_t &nfa, nfa_state_t *n)
Definition: nfa.cc:58
uint32_t size
Definition: nfa.h:78
nfa_state_t * compile(nfa_t &nfa, nfa_state_t *n)
Definition: nfa.cc:32
virtual nfa_state_t * compile(nfa_t &nfa, nfa_state_t *n)=0
struct re2c::nfa_state_t::@6::@10 fin
nfa_state_t * compile(nfa_t &nfa, nfa_state_t *n)
Definition: nfa.cc:39
RegExp * ctx
Definition: regexp_rule.h:22
nfa_state_t * compile(nfa_t &nfa, nfa_state_t *n)
Definition: nfa.cc:24
struct re2c::nfa_state_t::@6::@7 alt
virtual uint32_t calc_size() const =0
struct re2c::nfa_state_t::@6::@9 ctx
~nfa_t()
Definition: nfa.cc:19
Range * ran
Definition: nfa.h:34
Definition: bitmap.cc:10
nfa_state_t * states
Definition: nfa.h:79