Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Of AST and YAL

5 views
Skip to first unread message

Leopold Toetsch

unread,
Sep 7, 2003, 12:36:57 PM9/7/03
to P6I
I'm currently investigating the AST (abstract syntax tree) interface for
Parrot. For getting a feeling, how this could look like, I've
implemented (some parts) of Yet Another Language (YAL).

The dump below is a visual representation of the AST. The -o (optimize)
option does some constant folding and optimizes e.g. C<if> and C<while>
for constants.

The question is, if and where I should commit it. Its currently totally
standalone, so I can tar and send it per PM too.

Comments welcome,
leo

Some examples:

$ cat a.i
int main()
{
double x = 4.1 + 2;
print x + 10;
if (2 + 1 == 2 + 100) {
print x;
}
}

$ ./pir -o <a.i
.pcc_sub _main prototyped
.sym float x
x = 6.1
add $N1, x, 10
print $N1
end
.end

$ ./pir -d -o <a.i

(sub
(decl
(const I)
(id main))
(block
(seq
(seq
(=
(decl
(const N)
(id x))
(const 6.1))
(print
(add
(id x)
(const 10))))
(noop))))

$ cat b.i
int main()
{
var x;
print x + 10;
}

$ ./pir -o <b.i
.pcc_sub _main prototyped
new_pad 0
.sym PerlUndef x
x = new PerlUndef
store_lex -1, "x", x
$P1 = new PerlUndef
add $P1, x, 10
print $P1
pop_pad
end
.end

Michal Wallace

unread,
Sep 7, 2003, 8:01:07 PM9/7/03
to Leopold Toetsch, P6I
On Sun, 7 Sep 2003, Leopold Toetsch wrote:

> I'm currently investigating the AST (abstract syntax tree) interface
> for Parrot. For getting a feeling, how this could look like, I've
> implemented (some parts) of Yet Another Language (YAL).

I like it. What is this written in? C or Perl or what?
If it's in perl (or python of course) I'd like to merge
in all the pirate code generation stuff.

(My plan for this week was to do something very similar,
and try to get a simple lisplike language to integrate
with python)

Sincerely,

Michal J Wallace
Sabren Enterprises, Inc.
-------------------------------------
contact: mic...@sabren.com
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
--------------------------------------


Leopold Toetsch

unread,
Sep 8, 2003, 3:48:23 AM9/8/03
to Michal Wallace, perl6-i...@perl.org
Michal Wallace <mic...@sabren.com> wrote:
> On Sun, 7 Sep 2003, Leopold Toetsch wrote:

>> I'm currently investigating the AST (abstract syntax tree) interface
>> for Parrot. For getting a feeling, how this could look like, I've
>> implemented (some parts) of Yet Another Language (YAL).

> I like it. What is this written in? C or Perl or what?
> If it's in perl (or python of course) I'd like to merge
> in all the pirate code generation stuff.

Its C only, sorry.

> (My plan for this week was to do something very similar,
> and try to get a simple lisplike language to integrate
> with python)

I'm thinking of a AST text interface for imcc/parrot too. The lispish
AST-dump produced by YAL is handy for debugging and testing, and it can
be parsed easily to reconstruct the AST again.

> Sincerely,
>
> Michal J Wallace

leo

James Michael Dupont

unread,
Sep 8, 2003, 6:22:11 AM9/8/03
to l...@toetsch.at, Michal Wallace, perl6-i...@perl.org
--- Leopold Toetsch <l...@toetsch.at> wrote:

> Michal Wallace <mic...@sabren.com> wrote:
> > (My plan for this week was to do something very similar,
> > and try to get a simple lisplike language to integrate
> > with python)
>
> I'm thinking of a AST text interface for imcc/parrot too. The lispish
> AST-dump produced by YAL is handy for debugging and testing, and it
> can
> be parsed easily to reconstruct the AST again.

OK. This is where I would like to get involved. Currently I have been
working on documenting the GCC ast, in hopes of making that generatly
useful.
See my last mail about that here :
http://sourceforge.net/mailarchive/forum.php?thread_id=3080551&forum_id=7974

My plan is to make a generic RDF interface to save, manip. and restore
ASTS. This will also include some of the parrot languages.

The redland rdf api provides a good C api into rdf.

The advantages of using rdf instead of a homegrown format are the
amount of tools available, you then have filters, and visualization
tools immediatly available.

Later on when we have a two-way gateway, then you will be able to use a
proof engines to do rule-based tweaking of your AST before sending this
off to the backend for execution.

The other advantage of using redland is that you can exchange ASTs in
memory or using one of the storage systems that plug-in like the
berkleydb interface. That allows high-speed exchange of large amounts
of ASTS.

I hope that you do not get annoyed at this suggestion, if you feel it
is off topic, please tell me.

Thanks,
mike

=====
James Michael DuPont
http://introspector.sourceforge.net/

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Leopold Toetsch

unread,
Sep 8, 2003, 4:00:41 PM9/8/03
to James Michael DuPont, perl6-i...@perl.org
James Michael DuPont wrote:


> The redland rdf api provides a good C api into rdf.
>
> The advantages of using rdf instead of a homegrown format are the
> amount of tools available, you then have filters, and visualization
> tools immediatly available.

First I have to admit: I don't like XML. Second I don't want an external
library at such a central place inside Parrot. I also think (hvaing a
short look at redland-0.9.14, that this might be some overkill to use
that as the AST interface for parrot.

OTOH ...


> Later on when we have a two-way gateway, then you will be able to use a
> proof engines to do rule-based tweaking of your AST before sending this
> off to the backend for execution.

... ab interface to RDF would be for sure a nice to have.


> I hope that you do not get annoyed at this suggestion, if you feel it
> is off topic, please tell me.

No, not at all. Thanks for your input.


> Thanks,
> mike
leo


James Michael Dupont

unread,
Sep 9, 2003, 1:33:40 AM9/9/03
to Leopold Toetsch, perl6-i...@perl.org
--- Leopold Toetsch <l.to...@nextra.at> wrote:
> James Michael DuPont wrote:
>
>
> > The redland rdf api provides a good C api into rdf.
> >
> > The advantages of using rdf instead of a homegrown format are the
> > amount of tools available, you then have filters, and visualization
> > tools immediatly available.
>
> First I have to admit: I don't like XML.

I dont either. ;) XML sucks. Logic rulez.

I have been using timbls n3 notation
http://www.w3.org/2000/10/swap/Primer

>Second I don't want an
> external
> library at such a central place inside Parrot.

Yes. We can make a native structure.

The only thing is this basic api. We dont need to

1. you represent the ast as a set of triples (maybe quads with context)
so each thing is a statement like :
subject predicate object [context].

2. You can transform or flatten any ast into a set of triples
that is the only real support that I need from you. Basically a set of
functions that can be used to emit any ast as a set of logical
statements.

The logical statements can just be parrot arrays and the user can
figure out what to do with them.

3. you can build an ast out of such triples.
The only support needed is to have some way to lookup the type of
predicate by a name, or to reference an ast node by id. Then we can
write various parser in parrot that use this api. I guess the input
could also be a parrot array with three columns.

4. You register new predicate names (i have been extracting them from
the gcc)
you can see some of those here
http://introspector.sourceforge.net/2003/09/ildasm_header_micront.owl

That could also be an array of known predicates. Each statement could
just contain the index to them.

5. we dont need an rdf parser or n3 parser, but can factor that out
like redland does :

in fact, the only api needed to be implemented is the rdf.storage and
rdf.model. those two represent the parsed state of an rdf document and
the way to interface to the representation. The rest can be left out of
the core.


>I also think (hvaing a
>
> short look at redland-0.9.14, that this might be some overkill to use
>
> that as the AST interface for parrot.

yes. We can make a very cut down api and simple (parrot) provider for
n3.
The Eulersharp code can be compiled later to parrot via dotgnu.
http://eulersharp.sourceforge.net/2003/03swap/


>
> OTOH ...
>
>
> > Later on when we have a two-way gateway, then you will be able to
> use a
> > proof engines to do rule-based tweaking of your AST before sending
> this
> > off to the backend for execution.
>
> ... ab interface to RDF would be for sure a nice to have.

Yes, I am really interested in the ability to plug in a proof engine
and feed it rules to tweak the code. The format is really *egal*.
(sorry for the extreme-denglishing)

>
>
> > I hope that you do not get annoyed at this suggestion, if you feel
> it
> > is off topic, please tell me.
>
> No, not at all. Thanks for your input.

Ok, then you get more. :)

schöne Grüsse aus Frankfurt am Main,

Leopold Toetsch

unread,
Sep 11, 2003, 9:37:11 AM9/11/03
to perl6-i...@perl.org
Leopold Toetsch <l.to...@nextra.at> wrote:
> I'm currently investigating the AST (abstract syntax tree) interface for
> Parrot. For getting a feeling, how this could look like, I've
> implemented (some parts) of Yet Another Language (YAL).

I have put version yal-0.02 on my webpage. You can get it at:
http://toetsch.at/yal/
http://toetsch.at/yal/yal-0.02.tgz

Have fun & comments welcome,
leo

0 new messages