Jump to content    • Log In with Google      Sign In      •
Create Account     King Mir  Member Since 11 Jun 2006 Offline
Last Active Dec 13 2014 05:04 PM  Topics I've Started  Help me
with my design  05 December 2013 - 11:25 PM   I'm writing a
compiler, and I'm trying to come up with a good design for an
abstract syntax tree, and it's conversion into code.   The
Problem The AST is built in depth first order, such that every
node added will only ever refer to previously added nodes, and
in most cases referenced nodes are the most recently added
nodes. It is naturally a tree, so each node except the root node
is referenced by one parent. For data, an AST node has a type,
which can optionally be represented as an enum, a string value,
and references to a usually small number of other nodes.  The
above naturally leads to an implementation of a std::deque of
nodes, acting like a stack. This takes advantage of the fact
that elements in a deque tend to be adjacent in memory. It also
allows the tree to grow without