From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Data structures for syntax trees
Date: Mon, 1 Feb 2010 21:03:44 +0100
Date: 2010-02-01T21:03:43+01:00 [thread overview]
Message-ID: <ewi5fv1j10xz$.17srdk0kkvyoe.dlg@40tude.net> (raw)
In-Reply-To: 20100201213441.503839d5.tero.koskinen@iki.fi
On Mon, 1 Feb 2010 21:34:41 +0200, Tero Koskinen wrote:
> And what kind of data structures others have used to present
> syntax trees?
I am using access types to non-controlled class-wide objects allocated in
an arena pool. A syntax tree is usually removed as a whole.
Tree_Pool : Stack_Storage.Pool (2048, 128);
type Node is abstract tagged limited null record;
function Image (Item : Node) return String is abstract;
type Node_Ptr is access Node'Class;
for Node_Ptr'Storage_Pool use Tree_Pool;
type Term is abstract new Node with record
Location : Parsers.Multiline_Source.Location;
end record;
type Expression (Count : Positive) is new Node with record
Operation : Operations;
Location : Parsers.Multiline_Source.Location;
Operands : Argument_List (1..Count);
end record;
And so on. The example can be found here:
http://www.dmitry-kazakov.de/ada/components.htm#12.9
I cannot tell if that works with Janus, I don't have the compiler.
Alternatively I would use a directed graph. That again would be access
types to the arena pool of the graph nodes, parent-child relations
maintained implicitly by the pool.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
prev parent reply other threads:[~2010-02-01 20:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-01 19:34 Data structures for syntax trees Tero Koskinen
2010-02-01 20:03 ` Dmitry A. Kazakov [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox