[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [DotGNU]Can treecc help me?
From: |
Rhys Weatherley |
Subject: |
Re: [DotGNU]Can treecc help me? |
Date: |
Mon, 3 Feb 2003 07:26:50 +1000 |
User-agent: |
KMail/1.4.3 |
Treecc works best where there are common operations across the entire set of
nodes. Also, each case needs to be relatively independent. That is, the
operation for a particular node type should be written in terms of just the
fields in the node, and recursive calls on the children.
Binge may be a good candidate for this - I'd have to study it more closely.
The generators could probably be turned into node operations fairly easily.
The nodes themselves in Binge.Bits are currently a mixture of data and utility
routines. The utility routines would have to be ejected to somewhere else,
as either node operations, or static methods in some separate utility class.
> Currently, I am using a
> visitor pattern with a little mix of the inheritance pattern. I've
> seriously thought about moving to an inheritance pattern completely, but
> now I'm in doubt. Let me describe Binge a little more:
Treecc allows you to easily switch between the inheritance and visitor styles.
Or have some operations be inheritance, and others be visitors.
> I don't entirely understand treecc. It seems that you write input files
> for treecc that use an internal treecc language and then treecc will
> generate scaffolding for your compiler in whatever output language you
> choose. Surely, this scaffolding is just stub code and you'd have to
> actually modify the scaffolding to produce a compiler ... but then you are
> likely to regenerate the scaffolding as you flesh out the compiler so then
> you'd have to reinsert the implementation code ... What am I missing?
It doesn't generate scaffolding that you then modify. It is similar to bison
in that you insert the implementation code directly into the input files, and
the tool generates the final scaffolding+implementation. Consider the
following from CSConverter.cs:
public override void Convert (Field field)
{
field.TargetName = ReservedName (field.NativeName);
}
This would turn into something like this:
%node BingeObject %abstract %typedef
%node Field BingeObject = { ... }
%operation %virtual void CSConvert(BingeObject this)
CSConvert(Field)
{
this.TargetName = ReservedName (this.NativeName);
}
As you can see, the original code is in the treecc input, and will get
inserted at the correct place when treecc is run. You then compile the
output as-is. There is no need to modify the output further.
As Gopal mentioned, you may want to have a look at the JScript code, as it
shows using treecc in C# on a substantial system.
Cheers,
Rhys.