Re: Perl Abstract/Concrete Syntax Tree

2003-12-30 Thread Rafael Garcia-Suarez
Andrew Potozniak wrote in perl.qa :
>   I was wondering if there was anything built in Perl (a Module) that
> will take in a Perl file and parse that into an abstract or concrete syntax
> tree.  I searched around cpan for a bit and couldn't find what I was looking
> for.  If anyone is wondering what I'm talking about there is a nice Java
> package that Eclipse uses to create a tree for Java compilation that I can
> point you toward.  Thanks for your time.

Hm -- as the task of parsing perl involves some complex interplay
between compile-time and run-time -- think about the function
prototypes, for example -- perl can't be described by a non-ambiguous
grammar, and can't be parsed accurately by tools that don't include
a full-fledged perl interpreter already.

However, during parsing, perl builds internally an abstract syntax tree
for its own usage ; the syntax tree is then walked during execution.
It's possible to stop the perl interpreter after the compilation of the
main program and to have it print the current contents of the parse
tree. This is achieved by the O and B::* modules, that come with perl.
You may want something not too far from this :

$ perl -MO=Concise -e 'print $a + $b'
8  <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
7 <@> print vK ->8
3<0> pushmark s ->4
6<2> add[t1] sK/2 ->7
-   <1> ex-rv2sv sK/1 ->5
4  <$> gvsv(*a) s ->5
-   <1> ex-rv2sv sK/1 ->6
5  <$> gvsv(*b) s ->6
-e syntax OK

See the docs for O, B and B::Concise for more information.


Re: Perl Abstract/Concrete Syntax Tree

2003-12-30 Thread Ovid
--- "Potozniak, Andrew" <[EMAIL PROTECTED]> wrote:
> Hi,
> 
>   I was wondering if there was anything built in Perl (a Module) that
> will take in a Perl file and parse that into an abstract or concrete
> syntax
> tree.  I searched around cpan for a bit and couldn't find what I was
> looking
> for.  If anyone is wondering what I'm talking about there is a nice
> Java
> package that Eclipse uses to create a tree for Java compilation that
> I can
> point you toward.  Thanks for your time.
> 
> ~~Andrew  

Andrew,

I'm a bit confused.  Eclipse is simply an IDE, so that doesn't help me
understand what you're looking for.

As for turning a file into a "syntax tree", what do you mean?  Files
are in many different formats.  I can't imagine a single module
handling CSV, XML, and binary JPEG files the same way.  If you could be
a bit more concrete in what you are looking for, we would be better
prepared to help.  Perhaps if you could send a code snippet of what you
would *like* Perl to do (and specify the file format(s) that you want
to work with).

Cheers,
Ovid

=
Silence is Evilhttp://users.easystreet.com/ovid/philosophy/indexdecency.htm
Ovid   http://www.perlmonks.org/index.pl?node_id=17000
Web Programming with Perl  http://users.easystreet.com/ovid/cgi_course/


Perl Abstract/Concrete Syntax Tree

2003-12-30 Thread Potozniak, Andrew
Hi,

I was wondering if there was anything built in Perl (a Module) that
will take in a Perl file and parse that into an abstract or concrete syntax
tree.  I searched around cpan for a bit and couldn't find what I was looking
for.  If anyone is wondering what I'm talking about there is a nice Java
package that Eclipse uses to create a tree for Java compilation that I can
point you toward.  Thanks for your time.

~~Andrew