lexer.hpp
字号:
: node(x) , m_left(x.m_left->clone()) , m_right(x.m_right->clone()){}inline node *cat_node::clone() const{ return new cat_node(m_left->clone(), m_right->clone());}inline boolcat_node::nullable() const{ return m_left->nullable() && m_right->nullable();}inline node_setcat_node::firstpos() const{ if (m_left->nullable()) { node_set rval; node_set l = m_left->firstpos(); node_set r = m_right->firstpos(); std::set_union(l.begin(), l.end(), r.begin(), r.end(), std::inserter(rval, rval.begin())); return rval; } else { return m_left->firstpos(); }}inline node_setcat_node::lastpos() const{ if (m_right->nullable()) { node_set rval; node_set l = m_left->lastpos(); node_set r = m_right->lastpos(); std::set_union(l.begin(), l.end(), r.begin(), r.end(), std::inserter(rval, rval.begin())); return rval; } else { return m_right->lastpos(); }}inline voidcat_node::compute_followpos(followpos_t& followpos) const{ node_set l = m_left->lastpos(); for (node_set::iterator i = l.begin(); i != l.end(); ++i) { node_set rf = m_right->firstpos(); followpos[*i].insert(rf.begin(), rf.end()); } m_left->compute_followpos(followpos); m_right->compute_followpos(followpos);}inline voidcat_node::compute_state_match(state_match_t& state_match) const{ m_left->compute_state_match(state_match); m_right->compute_state_match(state_match);}inline voidcat_node::get_eof_ids(node_set& eof_nodes) const{ m_left->get_eof_ids(eof_nodes); m_right->get_eof_ids(eof_nodes);}inline voidcat_node::assign_node_ids(node_id_t& node_count){ m_left->assign_node_ids(node_count); m_right->assign_node_ids(node_count);}#if defined(BOOST_SPIRIT_DEBUG) && (BOOST_SPIRIT_DEBUG_FLAGS & BOOST_SPIRIT_DEBUG_FLAGS_SLEX)inline voidcat_node::dump(std::ostream& out) const{ m_left->dump(out); out << "\ncat_node"; out << " nullable() = " << (nullable() ? "true" : "false"); out << " firstpos() = "; node_set fp = firstpos(); std::copy(fp.begin(), fp.end(), std::ostream_iterator<node_id_t>(out, ",")); out << " lastpos() = "; node_set lp = lastpos(); std::copy(lp.begin(), lp.end(), std::ostream_iterator<node_id_t>(out, ",")); m_right->dump(out);}#endifclass star_node : public node{public: star_node(node* left); star_node(const star_node& x); virtual ~star_node(){} virtual node* clone() const; virtual bool nullable() const; virtual node_set firstpos() const; virtual node_set lastpos() const; virtual void compute_followpos(followpos_t& followpos) const; virtual void compute_state_match(state_match_t& state_match ) const; virtual void get_eof_ids(node_set& eof_set) const; virtual void assign_node_ids(node_id_t& node_count);#if defined(BOOST_SPIRIT_DEBUG) && (BOOST_SPIRIT_DEBUG_FLAGS & BOOST_SPIRIT_DEBUG_FLAGS_SLEX) virtual void dump(std::ostream& out) const;#endifprivate: std::auto_ptr<node> m_left;};inlinestar_node::star_node(node* left) : node() , m_left(left){}inlinestar_node::star_node(const star_node& x) : node(x) , m_left(x.m_left->clone()){}inline node *star_node::clone() const{ return new star_node(m_left->clone());}inline boolstar_node::nullable() const{ return true;}inline node_setstar_node::firstpos() const{ return m_left->firstpos();}inline node_setstar_node::lastpos() const{ return m_left->lastpos();}inline voidstar_node::compute_followpos(followpos_t& followpos) const{ node_set lp = this->lastpos(); for (node_set::iterator i = lp.begin(); i != lp.end(); ++i) { node_set fp = this->firstpos(); followpos[*i].insert(fp.begin(), fp.end()); } m_left->compute_followpos(followpos);}inline voidstar_node::compute_state_match(state_match_t& state_match) const{ m_left->compute_state_match(state_match);}inline voidstar_node::get_eof_ids(node_set& eof_nodes) const{ m_left->get_eof_ids(eof_nodes);}inline voidstar_node::assign_node_ids(node_id_t& node_count){ m_left->assign_node_ids(node_count);}#if defined(BOOST_SPIRIT_DEBUG) && (BOOST_SPIRIT_DEBUG_FLAGS & BOOST_SPIRIT_DEBUG_FLAGS_SLEX)inline voidstar_node::dump(std::ostream& out) const{ m_left->dump(out); out << "\nstar_node"; out << " nullable() = " << (nullable() ? "true" : "false"); out << " firstpos() = "; node_set fp = firstpos(); std::copy(fp.begin(), fp.end(), std::ostream_iterator<node_id_t>(out, ",")); out << " lastpos() = "; node_set lp = lastpos(); std::copy(lp.begin(), lp.end(), std::ostream_iterator<node_id_t>(out, ","));}#endifclass eof_node : public node{public: eof_node(); eof_node(const eof_node& x); virtual ~eof_node(){} virtual node* clone() const; virtual bool nullable() const; virtual node_set firstpos() const; virtual node_set lastpos() const; virtual void compute_followpos(followpos_t& followpos) const; virtual void compute_state_match(state_match_t& state_match ) const; virtual void get_eof_ids(node_set& eof_set) const; virtual void assign_node_ids(node_id_t& node_count);#if defined(BOOST_SPIRIT_DEBUG) && (BOOST_SPIRIT_DEBUG_FLAGS & BOOST_SPIRIT_DEBUG_FLAGS_SLEX) virtual void dump(std::ostream& out) const;#endifprivate: node_id_t m_node_num;};inlineeof_node::eof_node() : node() , m_node_num(0){}inlineeof_node::eof_node(const eof_node& x) : node(x) , m_node_num(x.m_node_num){}inline node *eof_node::clone() const{ return new eof_node(*this);}inline booleof_node::nullable() const{ return false;}inline node_seteof_node::firstpos() const{ node_set rval; rval.insert(m_node_num); return rval;}inline node_seteof_node::lastpos() const{ node_set rval; rval.insert(m_node_num); return rval;}inline voideof_node::compute_followpos(followpos_t&) const{ return;}inline voideof_node::compute_state_match(state_match_t& state_match) const{ if (state_match.size() < m_node_num + 1) state_match.resize(m_node_num + 1); state_match[m_node_num].resize(256, 0);}inline voideof_node::get_eof_ids(node_set& eof_nodes) const{ eof_nodes.insert(m_node_num);}inline voideof_node::assign_node_ids(node_id_t& node_count){ m_node_num = node_count++;}#if defined(BOOST_SPIRIT_DEBUG) && (BOOST_SPIRIT_DEBUG_FLAGS & BOOST_SPIRIT_DEBUG_FLAGS_SLEX)inline voideof_node::dump(std::ostream& out) const{ out << "\neof_node"; out << " m_node_num = " << m_node_num; out << " nullable() = " << (nullable() ? "true" : "false"); out << " firstpos() = "; node_set fp = firstpos(); std::copy(fp.begin(), fp.end(), std::ostream_iterator<node_id_t>(out, ",")); out << " lastpos() = "; node_set lp = lastpos(); std::copy(lp.begin(), lp.end(), std::ostream_iterator<node_id_t>(out, ","));}#endifclass ccl_node : public node{public: ccl_node(const std::vector<uchar>& v); ccl_node(const uchar c1, const uchar c2); ccl_node(const ccl_node& x); virtual ~ccl_node(){} virtual node* clone() const; virtual bool nullable() const; virtual node_set firstpos() const; virtual node_set lastpos() const; virtual void compute_followpos(followpos_t& followpos) const; virtual void compute_state_match(state_match_t& state_match ) const; virtual void get_eof_ids(node_set& eof_set) const; virtual void assign_node_ids(node_id_t& node_count);#if defined(BOOST_SPIRIT_DEBUG) && (BOOST_SPIRIT_DEBUG_FLAGS & BOOST_SPIRIT_DEBUG_FLAGS_SLEX) virtual void dump(std::ostream& out) const;#endifprivate: std::vector<uchar> m_match; node_id_t m_node_num;};inlineccl_node::ccl_node(const std::vector<uchar>& v) : node() , m_match(v) , m_node_num(0){ m_match.resize(256); // make sure it's the right size}inlineccl_node::ccl_node(const uchar c1, const uchar c2) : node() , m_match(256, uchar(0)) , m_node_num(0){ BOOST_ASSERT(c1 < c2); for (std::size_t i = c1; i <= std::size_t(c2); ++i) { m_match[i] = 1; }}inlineccl_node::ccl_node(const ccl_node& x) : node(x) , m_match(x.m_match) , m_node_num(x.m_node_num){}inline node *ccl_node::clone() const{ return new ccl_node(*this);}inline boolccl_node::nullable() const{ return false;}inline node_setccl_node::firstpos() const{ node_set rval; rval.insert(m_node_num); return rval;}inline node_setccl_node::lastpos() const{ return firstpos();}inline voidccl_node::compute_followpos(followpos_t&) const{ return;}inline voidccl_node::compute_state_match(state_match_t& state_match) const{ if (state_match.size() < m_node_num + 1) state_match.resize(m_node_num + 1); state_match[m_node_num] = m_match;}inline voidccl_node::get_eof_ids(node_set&) const{ return;}inline voidccl_node::assign_node_ids(node_id_t& node_count){ m_node_num = node_count++;}#if defined(BOOST_SPIRIT_DEBUG) && (BOOST_SPIRIT_DEBUG_FLAGS & BOOST_SPIRIT_DEBUG_FLAGS_SLEX)inline voidccl_node::dump(std::ostream& out) const{ out << "\nccl_node m_match = "; for (std::size_t i = 0; i < m_match.size(); ++i) { if (m_match[i]) out << i << ", "; } out << " m_node_num = " << m_node_num; out << " nullable() = " << (nullable() ? "true" : "false"); out << " firstpos() = "; node_set fp = firstpos(); std::copy(fp.begin(), fp.end(), std::ostream_iterator<node_id_t>(out, ",")); out << " lastpos() = "; node_set lp = lastpos(); std::copy(lp.begin(), lp.end(), std::ostream_iterator<node_id_t>(out, ","));}#endiftemplate <typename ScannerT>class make_concat{ typedef typename ScannerT::iterator_t iterator_type;public: make_concat(std::stack<node*>& the_stack) : m_stack(the_stack) {} void operator()(iterator_type const &, iterator_type const &) const { node* right = m_stack.top(); m_stack.pop(); node* left = m_stack.top(); m_stack.pop(); node* newnode = new cat_node(left, right); m_stack.push(newnode);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -