Perl5 AST

R

romerun

Hi All,

I have been wondering for a long time if there exists any abstract
syntax tree parser for Perl5 or any attempt to create it. In the CPAN
there are some B:: modules that can give some kinds of Perl5 OP tree,
which loses some important information to do some static checking such
as type checking via type annotation, reference leaking, unreachable
code, etc. Any suggest on where should I look ?

-thanks
kem
 
B

Ben Morrow

Quoth (e-mail address removed):
Hi All,

I have been wondering for a long time if there exists any abstract
syntax tree parser for Perl5 or any attempt to create it. In the CPAN
there are some B:: modules that can give some kinds of Perl5 OP tree,
which loses some important information to do some static checking such
as type checking via type annotation, reference leaking, unreachable
code, etc. Any suggest on where should I look ?

You could try looking at PPI, though that's more of a parser than an AST
builder. perl doesn't really have any intermadiate steps between parsing
the source and building the OP tree, so all the information that's kept
is available there; OTOH you may find something useful in the MAD stuff
that's gone into blead recently as the beginning of a p5-p6 converter.
IIRC it comes with a lot of caveats, though, like 'this doesn't really
work yet' and 'perl built with this option is not compatible with perl
built without'.

Ben
 
U

Uri Guttman

r> I have been wondering for a long time if there exists any abstract
r> syntax tree parser for Perl5 or any attempt to create it. In the CPAN
r> there are some B:: modules that can give some kinds of Perl5 OP tree,
r> which loses some important information to do some static checking such
r> as type checking via type annotation, reference leaking, unreachable
r> code, etc. Any suggest on where should I look ?

perl 6 will be able to do that and partly already. larry wall is working
on that and also the PPI modules can do a decent text analysis of perl5
code.

uri
 
R

Randal L. Schwartz

romerun> I have been wondering for a long time if there exists any abstract
romerun> syntax tree parser for Perl5 or any attempt to create it. In the CPAN
romerun> there are some B:: modules that can give some kinds of Perl5 OP tree,
romerun> which loses some important information to do some static checking such
romerun> as type checking via type annotation, reference leaking, unreachable
romerun> code, etc. Any suggest on where should I look ?

You *are* aware that it's impossible to lex perl without actually being
prepared to execute Perl code, right?

Perl cannot be "statically analyzed".

.... http://www.perlmonks.org/index.pl?node=44722

And this is also true for Perl6. As long as / has two meanings (divide and
regex start, which hasn't changed for perl6), you need to know what state
you're in when you hit the char to know if it's standalone or the beginning of
something. And that can affect the entire rest of the program.

print "Just another Perl hacker,"; # the original
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top