Fix typo in grammar.
Add lexertl.
This commit is contained in:
112
inc/lexertl/parser/tree/end_node.hpp
Normal file
112
inc/lexertl/parser/tree/end_node.hpp
Normal file
@@ -0,0 +1,112 @@
|
||||
// end_node.hpp
|
||||
// Copyright (c) 2005-2012 Ben Hanson (http://www.benhanson.net/)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#ifndef LEXERTL_END_NODE_HPP
|
||||
#define LEXERTL_END_NODE_HPP
|
||||
|
||||
#include "node.hpp"
|
||||
#include "../../size_t.hpp"
|
||||
|
||||
namespace lexertl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename id_type>
|
||||
class basic_end_node : public basic_node<id_type>
|
||||
{
|
||||
public:
|
||||
typedef basic_node<id_type> node;
|
||||
typedef typename node::bool_stack bool_stack;
|
||||
typedef typename node::const_node_stack const_node_stack;
|
||||
typedef typename node::node_ptr_vector node_ptr_vector;
|
||||
typedef typename node::node_stack node_stack;
|
||||
typedef typename node::node_type node_type;
|
||||
typedef typename node::node_vector node_vector;
|
||||
|
||||
basic_end_node (const id_type id_, const id_type user_id_,
|
||||
const id_type next_dfa_, const id_type push_dfa_,
|
||||
const bool pop_dfa_) :
|
||||
basic_node<id_type> (false),
|
||||
_id (id_),
|
||||
_user_id (user_id_),
|
||||
_next_dfa (next_dfa_),
|
||||
_push_dfa (push_dfa_),
|
||||
_pop_dfa (pop_dfa_),
|
||||
_followpos ()
|
||||
{
|
||||
basic_node<id_type>::_firstpos.push_back (this);
|
||||
basic_node<id_type>::_lastpos.push_back (this);
|
||||
}
|
||||
|
||||
virtual ~basic_end_node ()
|
||||
{
|
||||
}
|
||||
|
||||
virtual node_type what_type () const
|
||||
{
|
||||
return node::END;
|
||||
}
|
||||
|
||||
virtual bool traverse (const_node_stack &/*node_stack_*/,
|
||||
bool_stack &/*perform_op_stack_*/) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual const node_vector &followpos () const
|
||||
{
|
||||
// _followpos is always empty..!
|
||||
return _followpos;
|
||||
}
|
||||
|
||||
virtual bool end_state () const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual id_type id () const
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
virtual id_type user_id () const
|
||||
{
|
||||
return _user_id;
|
||||
}
|
||||
|
||||
virtual id_type next_dfa () const
|
||||
{
|
||||
return _next_dfa;
|
||||
}
|
||||
|
||||
virtual id_type push_dfa () const
|
||||
{
|
||||
return _push_dfa;
|
||||
}
|
||||
|
||||
virtual bool pop_dfa () const
|
||||
{
|
||||
return _pop_dfa;
|
||||
}
|
||||
|
||||
private:
|
||||
id_type _id;
|
||||
id_type _user_id;
|
||||
id_type _next_dfa;
|
||||
id_type _push_dfa;
|
||||
bool _pop_dfa;
|
||||
node_vector _followpos;
|
||||
|
||||
virtual void copy_node (node_ptr_vector &/*node_ptr_vector_*/,
|
||||
node_stack &/*new_node_stack_*/, bool_stack &/*perform_op_stack_*/,
|
||||
bool &/*down_*/) const
|
||||
{
|
||||
// Nothing to do, as end_nodes are not copied.
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
103
inc/lexertl/parser/tree/iteration_node.hpp
Normal file
103
inc/lexertl/parser/tree/iteration_node.hpp
Normal file
@@ -0,0 +1,103 @@
|
||||
// iteration_node.hpp
|
||||
// Copyright (c) 2005-2012 Ben Hanson (http://www.benhanson.net/)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#ifndef LEXERTL_ITERATION_NODE_HPP
|
||||
#define LEXERTL_ITERATION_NODE_HPP
|
||||
|
||||
#include "node.hpp"
|
||||
|
||||
namespace lexertl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename id_type>
|
||||
class basic_iteration_node : public basic_node<id_type>
|
||||
{
|
||||
public:
|
||||
typedef basic_node<id_type> node;
|
||||
typedef typename node::bool_stack bool_stack;
|
||||
typedef typename node::const_node_stack const_node_stack;
|
||||
typedef typename node::node_ptr_vector node_ptr_vector;
|
||||
typedef typename node::node_stack node_stack;
|
||||
typedef typename node::node_type node_type;
|
||||
typedef typename node::node_vector node_vector;
|
||||
|
||||
basic_iteration_node (basic_node<id_type> *next_, const bool greedy_) :
|
||||
basic_node<id_type> (true),
|
||||
_next (next_),
|
||||
_greedy (greedy_)
|
||||
{
|
||||
typename node_vector::iterator iter_;
|
||||
typename node_vector::iterator end_;
|
||||
|
||||
_next->append_firstpos (node::_firstpos);
|
||||
_next->append_lastpos (node::_lastpos);
|
||||
|
||||
for (iter_ = node::_lastpos.begin (), end_ = node::_lastpos.end ();
|
||||
iter_ != end_; ++iter_)
|
||||
{
|
||||
(*iter_)->append_followpos (node::_firstpos);
|
||||
}
|
||||
|
||||
for (iter_ = node::_firstpos.begin (), end_ = node::_firstpos.end ();
|
||||
iter_ != end_; ++iter_)
|
||||
{
|
||||
(*iter_)->greedy (greedy_);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~basic_iteration_node ()
|
||||
{
|
||||
}
|
||||
|
||||
virtual node_type what_type () const
|
||||
{
|
||||
return node::ITERATION;
|
||||
}
|
||||
|
||||
virtual bool traverse (const_node_stack &node_stack_,
|
||||
bool_stack &perform_op_stack_) const
|
||||
{
|
||||
perform_op_stack_.push (true);
|
||||
node_stack_.push (_next);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
// Not owner of this pointer...
|
||||
basic_node<id_type> *_next;
|
||||
bool _greedy;
|
||||
|
||||
virtual void copy_node (node_ptr_vector &node_ptr_vector_,
|
||||
node_stack &new_node_stack_, bool_stack &perform_op_stack_,
|
||||
bool &down_) const
|
||||
{
|
||||
if (perform_op_stack_.top ())
|
||||
{
|
||||
basic_node<id_type> *ptr_ = new_node_stack_.top ();
|
||||
|
||||
node_ptr_vector_->push_back
|
||||
(static_cast<basic_iteration_node<id_type> *>(0));
|
||||
node_ptr_vector_->back () = new basic_iteration_node
|
||||
(ptr_, _greedy);
|
||||
new_node_stack_.top () = node_ptr_vector_->back ();
|
||||
}
|
||||
else
|
||||
{
|
||||
down_ = true;
|
||||
}
|
||||
|
||||
perform_op_stack_.pop ();
|
||||
}
|
||||
|
||||
// No copy construction.
|
||||
basic_iteration_node (const basic_iteration_node &);
|
||||
// No assignment.
|
||||
const basic_iteration_node &operator = (const basic_iteration_node &);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
114
inc/lexertl/parser/tree/leaf_node.hpp
Normal file
114
inc/lexertl/parser/tree/leaf_node.hpp
Normal file
@@ -0,0 +1,114 @@
|
||||
// leaf_node.hpp
|
||||
// Copyright (c) 2005-2012 Ben Hanson (http://www.benhanson.net/)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#ifndef LEXERTL_LEAF_NODE_HPP
|
||||
#define LEXERTL_LEAF_NODE_HPP
|
||||
|
||||
#include "../../enums.hpp" // null_token
|
||||
#include "node.hpp"
|
||||
#include "../../size_t.hpp"
|
||||
|
||||
namespace lexertl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename id_type>
|
||||
class basic_leaf_node : public basic_node<id_type>
|
||||
{
|
||||
public:
|
||||
typedef basic_node<id_type> node;
|
||||
typedef typename node::bool_stack bool_stack;
|
||||
typedef typename node::const_node_stack const_node_stack;
|
||||
typedef typename node::node_ptr_vector node_ptr_vector;
|
||||
typedef typename node::node_stack node_stack;
|
||||
typedef typename node::node_type node_type;
|
||||
typedef typename node::node_vector node_vector;
|
||||
|
||||
basic_leaf_node (const id_type token_, const bool greedy_) :
|
||||
basic_node<id_type> (token_ == node::null_token ()),
|
||||
_token (token_),
|
||||
_set_greedy (!greedy_),
|
||||
_greedy (greedy_),
|
||||
_followpos ()
|
||||
{
|
||||
if (!node::_nullable)
|
||||
{
|
||||
node::_firstpos.push_back (this);
|
||||
node::_lastpos.push_back (this);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~basic_leaf_node ()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void append_followpos (const node_vector &followpos_)
|
||||
{
|
||||
for (typename node_vector::const_iterator iter_ = followpos_.begin (),
|
||||
end_ = followpos_.end (); iter_ != end_; ++iter_)
|
||||
{
|
||||
_followpos.push_back (*iter_);
|
||||
}
|
||||
}
|
||||
|
||||
virtual node_type what_type () const
|
||||
{
|
||||
return node::LEAF;
|
||||
}
|
||||
|
||||
virtual bool traverse (const_node_stack &/*node_stack_*/,
|
||||
bool_stack &/*perform_op_stack_*/) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual id_type token () const
|
||||
{
|
||||
return _token;
|
||||
}
|
||||
|
||||
virtual void greedy (const bool greedy_)
|
||||
{
|
||||
if (!_set_greedy)
|
||||
{
|
||||
_greedy = greedy_;
|
||||
_set_greedy = true;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool greedy () const
|
||||
{
|
||||
return _greedy;
|
||||
}
|
||||
|
||||
virtual const node_vector &followpos () const
|
||||
{
|
||||
return _followpos;
|
||||
}
|
||||
|
||||
virtual node_vector &followpos ()
|
||||
{
|
||||
return _followpos;
|
||||
}
|
||||
|
||||
private:
|
||||
id_type _token;
|
||||
bool _set_greedy;
|
||||
bool _greedy;
|
||||
node_vector _followpos;
|
||||
|
||||
virtual void copy_node (node_ptr_vector &node_ptr_vector_,
|
||||
node_stack &new_node_stack_, bool_stack &/*perform_op_stack_*/,
|
||||
bool &/*down_*/) const
|
||||
{
|
||||
node_ptr_vector_->push_back (static_cast<basic_leaf_node *>(0));
|
||||
node_ptr_vector_->back () = new basic_leaf_node (_token, _greedy);
|
||||
new_node_stack_.push (node_ptr_vector_->back ());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
241
inc/lexertl/parser/tree/node.hpp
Normal file
241
inc/lexertl/parser/tree/node.hpp
Normal file
@@ -0,0 +1,241 @@
|
||||
// node.hpp
|
||||
// Copyright (c) 2005-2012 Ben Hanson (http://www.benhanson.net/)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#ifndef LEXERTL_NODE_HPP
|
||||
#define LEXERTL_NODE_HPP
|
||||
|
||||
#include <assert.h>
|
||||
#include "../../containers/ptr_vector.hpp"
|
||||
#include "../../runtime_error.hpp"
|
||||
#include "../../size_t.hpp"
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
namespace lexertl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename id_type>
|
||||
class basic_node
|
||||
{
|
||||
public:
|
||||
enum node_type {LEAF, SEQUENCE, SELECTION, ITERATION, END};
|
||||
|
||||
typedef std::stack<bool> bool_stack;
|
||||
typedef std::stack<basic_node<id_type> *> node_stack;
|
||||
// stack and vector not owner of node pointers
|
||||
typedef std::stack<const basic_node<id_type> *> const_node_stack;
|
||||
typedef std::vector<basic_node<id_type> *> node_vector;
|
||||
typedef ptr_vector<basic_node<id_type> > node_ptr_vector;
|
||||
|
||||
basic_node () :
|
||||
_nullable (false),
|
||||
_firstpos (),
|
||||
_lastpos ()
|
||||
{
|
||||
}
|
||||
|
||||
basic_node (const bool nullable_) :
|
||||
_nullable (nullable_),
|
||||
_firstpos (),
|
||||
_lastpos ()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~basic_node ()
|
||||
{
|
||||
}
|
||||
|
||||
static id_type null_token ()
|
||||
{
|
||||
return static_cast<id_type>(~0);
|
||||
}
|
||||
|
||||
bool nullable () const
|
||||
{
|
||||
return _nullable;
|
||||
}
|
||||
|
||||
void append_firstpos (node_vector &firstpos_) const
|
||||
{
|
||||
firstpos_.insert (firstpos_.end (),
|
||||
_firstpos.begin (), _firstpos.end ());
|
||||
}
|
||||
|
||||
void append_lastpos (node_vector &lastpos_) const
|
||||
{
|
||||
lastpos_.insert (lastpos_.end (),
|
||||
_lastpos.begin (), _lastpos.end ());
|
||||
}
|
||||
|
||||
virtual void append_followpos (const node_vector &/*followpos_*/)
|
||||
{
|
||||
throw runtime_error ("Internal error node::append_followpos().");
|
||||
}
|
||||
|
||||
basic_node *copy (node_ptr_vector &node_ptr_vector_) const
|
||||
{
|
||||
basic_node *new_root_ = 0;
|
||||
const_node_stack node_stack_;
|
||||
bool_stack perform_op_stack_;
|
||||
bool down_ = true;
|
||||
node_stack new_node_stack_;
|
||||
|
||||
node_stack_.push (this);
|
||||
|
||||
while (!node_stack_.empty ())
|
||||
{
|
||||
while (down_)
|
||||
{
|
||||
down_ = node_stack_.top ()->traverse (node_stack_,
|
||||
perform_op_stack_);
|
||||
}
|
||||
|
||||
while (!down_ && !node_stack_.empty ())
|
||||
{
|
||||
const basic_node *top_ = node_stack_.top ();
|
||||
|
||||
top_->copy_node (node_ptr_vector_, new_node_stack_,
|
||||
perform_op_stack_, down_);
|
||||
|
||||
if (!down_) node_stack_.pop ();
|
||||
}
|
||||
}
|
||||
|
||||
assert (new_node_stack_.size () == 1);
|
||||
new_root_ = new_node_stack_.top ();
|
||||
new_node_stack_.pop ();
|
||||
return new_root_;
|
||||
}
|
||||
|
||||
virtual node_type what_type () const = 0;
|
||||
|
||||
virtual bool traverse (const_node_stack &node_stack_,
|
||||
bool_stack &perform_op_stack_) const = 0;
|
||||
|
||||
node_vector &firstpos ()
|
||||
{
|
||||
return _firstpos;
|
||||
}
|
||||
|
||||
const node_vector &firstpos () const
|
||||
{
|
||||
return _firstpos;
|
||||
}
|
||||
|
||||
// _lastpos modified externally, so not const &
|
||||
node_vector &lastpos ()
|
||||
{
|
||||
return _lastpos;
|
||||
}
|
||||
|
||||
virtual bool end_state () const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual id_type id () const
|
||||
{
|
||||
throw runtime_error ("Internal error node::id().");
|
||||
#ifdef __SUNPRO_CC
|
||||
// Stop bogus Solaris compiler warning
|
||||
return id_type ();
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual id_type user_id () const
|
||||
{
|
||||
throw runtime_error ("Internal error node::user_id().");
|
||||
#ifdef __SUNPRO_CC
|
||||
// Stop bogus Solaris compiler warning
|
||||
return id_type ();
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual id_type next_dfa () const
|
||||
{
|
||||
throw runtime_error ("Internal error node::next_dfa().");
|
||||
#ifdef __SUNPRO_CC
|
||||
// Stop bogus Solaris compiler warning
|
||||
return id_type ();
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual id_type push_dfa () const
|
||||
{
|
||||
throw runtime_error ("Internal error node::push_dfa().");
|
||||
#ifdef __SUNPRO_CC
|
||||
// Stop bogus Solaris compiler warning
|
||||
return id_type ();
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual bool pop_dfa () const
|
||||
{
|
||||
throw runtime_error ("Internal error node::pop_dfa().");
|
||||
#ifdef __SUNPRO_CC
|
||||
// Stop bogus Solaris compiler warning
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual id_type token () const
|
||||
{
|
||||
throw runtime_error ("Internal error node::token().");
|
||||
#ifdef __SUNPRO_CC
|
||||
// Stop bogus Solaris compiler warning
|
||||
return id_type ();
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void greedy (const bool /*greedy_*/)
|
||||
{
|
||||
throw runtime_error ("Internal error node::greedy(bool).");
|
||||
}
|
||||
|
||||
virtual bool greedy () const
|
||||
{
|
||||
throw runtime_error ("Internal error node::greedy().");
|
||||
#ifdef __SUNPRO_CC
|
||||
// Stop bogus Solaris compiler warning
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual const node_vector &followpos () const
|
||||
{
|
||||
throw runtime_error ("Internal error node::followpos().");
|
||||
#ifdef __SUNPRO_CC
|
||||
// Stop bogus Solaris compiler warning
|
||||
return firstpos;
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual node_vector &followpos ()
|
||||
{
|
||||
throw runtime_error ("Internal error node::followpos().");
|
||||
#ifdef __SUNPRO_CC
|
||||
// Stop bogus Solaris compiler warning
|
||||
return firstpos;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
const bool _nullable;
|
||||
node_vector _firstpos;
|
||||
node_vector _lastpos;
|
||||
|
||||
virtual void copy_node (node_ptr_vector &node_ptr_vector_,
|
||||
node_stack &new_node_stack_, bool_stack &perform_op_stack_,
|
||||
bool &down_) const = 0;
|
||||
|
||||
private:
|
||||
basic_node (const basic_node &); // No copy construction.
|
||||
const basic_node &operator = (const basic_node &); // No assignment.
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
106
inc/lexertl/parser/tree/selection_node.hpp
Normal file
106
inc/lexertl/parser/tree/selection_node.hpp
Normal file
@@ -0,0 +1,106 @@
|
||||
// selection_node.hpp
|
||||
// Copyright (c) 2005-2012 Ben Hanson (http://www.benhanson.net/)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#ifndef LEXERTL_SELECTION_NODE_HPP
|
||||
#define LEXERTL_SELECTION_NODE_HPP
|
||||
|
||||
#include "node.hpp"
|
||||
|
||||
namespace lexertl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename id_type>
|
||||
class basic_selection_node : public basic_node<id_type>
|
||||
{
|
||||
public:
|
||||
typedef basic_node<id_type> node;
|
||||
typedef typename node::bool_stack bool_stack;
|
||||
typedef typename node::const_node_stack const_node_stack;
|
||||
typedef typename node::node_ptr_vector node_ptr_vector;
|
||||
typedef typename node::node_stack node_stack;
|
||||
typedef typename node::node_type node_type;
|
||||
|
||||
basic_selection_node (basic_node<id_type> *left_,
|
||||
basic_node<id_type> *right_) :
|
||||
basic_node<id_type> (left_->nullable () || right_->nullable ()),
|
||||
_left (left_),
|
||||
_right (right_)
|
||||
{
|
||||
_left->append_firstpos (node::_firstpos);
|
||||
_right->append_firstpos (node::_firstpos);
|
||||
_left->append_lastpos (node::_lastpos);
|
||||
_right->append_lastpos (node::_lastpos);
|
||||
}
|
||||
|
||||
virtual ~basic_selection_node ()
|
||||
{
|
||||
}
|
||||
|
||||
virtual node_type what_type () const
|
||||
{
|
||||
return node::SELECTION;
|
||||
}
|
||||
|
||||
virtual bool traverse (const_node_stack &node_stack_,
|
||||
bool_stack &perform_op_stack_) const
|
||||
{
|
||||
perform_op_stack_.push (true);
|
||||
|
||||
switch (_right->what_type ())
|
||||
{
|
||||
case node::SEQUENCE:
|
||||
case node::SELECTION:
|
||||
case node::ITERATION:
|
||||
perform_op_stack_.push (false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
node_stack_.push (_right);
|
||||
node_stack_.push (_left);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
// Not owner of these pointers...
|
||||
basic_node<id_type> *_left;
|
||||
basic_node<id_type> *_right;
|
||||
|
||||
virtual void copy_node (node_ptr_vector &node_ptr_vector_,
|
||||
node_stack &new_node_stack_, bool_stack &perform_op_stack_,
|
||||
bool &down_) const
|
||||
{
|
||||
if (perform_op_stack_.top ())
|
||||
{
|
||||
basic_node<id_type> *rhs_ = new_node_stack_.top ();
|
||||
|
||||
new_node_stack_.pop ();
|
||||
|
||||
basic_node<id_type> *lhs_ = new_node_stack_.top ();
|
||||
|
||||
node_ptr_vector_->push_back
|
||||
(static_cast<basic_selection_node *>(0));
|
||||
node_ptr_vector_->back () = new basic_selection_node (lhs_, rhs_);
|
||||
new_node_stack_.top () = node_ptr_vector_->back ();
|
||||
}
|
||||
else
|
||||
{
|
||||
down_ = true;
|
||||
}
|
||||
|
||||
perform_op_stack_.pop ();
|
||||
}
|
||||
|
||||
// No copy construction.
|
||||
basic_selection_node (const basic_selection_node &);
|
||||
// No assignment.
|
||||
const basic_selection_node &operator = (const basic_selection_node &);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
126
inc/lexertl/parser/tree/sequence_node.hpp
Normal file
126
inc/lexertl/parser/tree/sequence_node.hpp
Normal file
@@ -0,0 +1,126 @@
|
||||
// sequence_node.hpp
|
||||
// Copyright (c) 2005-2012 Ben Hanson (http://www.benhanson.net/)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#ifndef LEXERTL_SEQUENCE_NODE_HPP
|
||||
#define LEXERTL_SEQUENCE_NODE_HPP
|
||||
|
||||
#include "node.hpp"
|
||||
|
||||
namespace lexertl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename id_type>
|
||||
class basic_sequence_node : public basic_node<id_type>
|
||||
{
|
||||
public:
|
||||
typedef basic_node<id_type> node;
|
||||
typedef typename node::bool_stack bool_stack;
|
||||
typedef typename node::const_node_stack const_node_stack;
|
||||
typedef typename node::node_ptr_vector node_ptr_vector;
|
||||
typedef typename node::node_stack node_stack;
|
||||
typedef typename node::node_type node_type;
|
||||
typedef typename node::node_vector node_vector;
|
||||
|
||||
basic_sequence_node (basic_node<id_type> *left_,
|
||||
basic_node<id_type> *right_) :
|
||||
basic_node<id_type> (left_->nullable () && right_->nullable ()),
|
||||
_left (left_),
|
||||
_right (right_)
|
||||
{
|
||||
_left->append_firstpos (node::_firstpos);
|
||||
|
||||
if (_left->nullable ())
|
||||
{
|
||||
_right->append_firstpos (node::_firstpos);
|
||||
}
|
||||
|
||||
if (_right->nullable ())
|
||||
{
|
||||
_left->append_lastpos (node::_lastpos);
|
||||
}
|
||||
|
||||
_right->append_lastpos (node::_lastpos);
|
||||
|
||||
node_vector &lastpos_ = _left->lastpos ();
|
||||
const node_vector &firstpos_ = _right->firstpos ();
|
||||
|
||||
for (typename node_vector::iterator iter_ = lastpos_.begin (),
|
||||
end_ = lastpos_.end (); iter_ != end_; ++iter_)
|
||||
{
|
||||
(*iter_)->append_followpos (firstpos_);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~basic_sequence_node ()
|
||||
{
|
||||
}
|
||||
|
||||
virtual node_type what_type () const
|
||||
{
|
||||
return node::SEQUENCE;
|
||||
}
|
||||
|
||||
virtual bool traverse (const_node_stack &node_stack_,
|
||||
bool_stack &perform_op_stack_) const
|
||||
{
|
||||
perform_op_stack_.push (true);
|
||||
|
||||
switch (_right->what_type ())
|
||||
{
|
||||
case node::SEQUENCE:
|
||||
case node::SELECTION:
|
||||
case node::ITERATION:
|
||||
perform_op_stack_.push (false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
node_stack_.push (_right);
|
||||
node_stack_.push (_left);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
// Not owner of these pointers...
|
||||
basic_node<id_type> *_left;
|
||||
basic_node<id_type> *_right;
|
||||
|
||||
virtual void copy_node (node_ptr_vector &node_ptr_vector_,
|
||||
node_stack &new_node_stack_, bool_stack &perform_op_stack_,
|
||||
bool &down_) const
|
||||
{
|
||||
if (perform_op_stack_.top ())
|
||||
{
|
||||
basic_node<id_type> *rhs_ = new_node_stack_.top ();
|
||||
|
||||
new_node_stack_.pop ();
|
||||
|
||||
basic_node<id_type> *lhs_ = new_node_stack_.top ();
|
||||
|
||||
node_ptr_vector_->push_back
|
||||
(static_cast<basic_sequence_node<id_type> *>(0));
|
||||
node_ptr_vector_->back () = new basic_sequence_node<id_type>
|
||||
(lhs_, rhs_);
|
||||
new_node_stack_.top () = node_ptr_vector_->back ();
|
||||
}
|
||||
else
|
||||
{
|
||||
down_ = true;
|
||||
}
|
||||
|
||||
perform_op_stack_.pop ();
|
||||
}
|
||||
|
||||
// No copy construction.
|
||||
basic_sequence_node (const basic_sequence_node &);
|
||||
// No assignment.
|
||||
const basic_sequence_node &operator = (const basic_sequence_node &);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user