D
Daniel Zinn
Hey,
I am not sure if I tried hard enough[1], but perhaps you can guide me, where
to go on with reading, or even propose some code sniplets. Ok, here is the
problem:
I want to analyze a Perl program. I want to transform every "line/statement"
of a given Perl script into a more abstract syntax which only deals with
function and variable definitions and calls/usage.
So, basicly my new "simplified" grammar looks like:
data Prog = Var VarName -- a variable is used
| Call FuncName -- a function is called
| Sub FuncName Prog -- FuncName is new function; body=Prog
| SubClos Prog -- an anom. function is created as closure
| Dyn VarName -- a "local" variable declaration
| Lex VarName -- a "my" variable declaration
| Block Prog -- just a { ... } block
| Skip -- something else
(sorry for this Haskell code over here, please don't feel offended )
So, since Perl is 'kind of' not easy to parse directly, I thought of using
the B module. After some browsing, it turned out that B::Xref is pretty
close. Unfortunately, I don't get the blocks, and the ordering is strange.
Since it should be very easy to get a representation like the one described
above, once you have the parse tree, I want to ask, if someone has some
experience with the B module(s). If not, it would be nice, if you could
point me to some readings where I could learn how to handle this framework.
Apart from this, I also want to do some variable assignment tracking, so I
really would like to understand how the Parse tree is organized and how you
can do transformation on it. So, is there any good place to start reading?
Thank you so much,
Daniel
[1] I experimented around with many B::???? modules,
tried to understand the B::Xref source code,
tired to figure out how to traverse the parse tree,
but could not find anything where to start, for example how to get this
tree at the first place...
I am not sure if I tried hard enough[1], but perhaps you can guide me, where
to go on with reading, or even propose some code sniplets. Ok, here is the
problem:
I want to analyze a Perl program. I want to transform every "line/statement"
of a given Perl script into a more abstract syntax which only deals with
function and variable definitions and calls/usage.
So, basicly my new "simplified" grammar looks like:
data Prog = Var VarName -- a variable is used
| Call FuncName -- a function is called
| Sub FuncName Prog -- FuncName is new function; body=Prog
| SubClos Prog -- an anom. function is created as closure
| Dyn VarName -- a "local" variable declaration
| Lex VarName -- a "my" variable declaration
| Block Prog -- just a { ... } block
| Skip -- something else
(sorry for this Haskell code over here, please don't feel offended )
So, since Perl is 'kind of' not easy to parse directly, I thought of using
the B module. After some browsing, it turned out that B::Xref is pretty
close. Unfortunately, I don't get the blocks, and the ordering is strange.
Since it should be very easy to get a representation like the one described
above, once you have the parse tree, I want to ask, if someone has some
experience with the B module(s). If not, it would be nice, if you could
point me to some readings where I could learn how to handle this framework.
Apart from this, I also want to do some variable assignment tracking, so I
really would like to understand how the Parse tree is organized and how you
can do transformation on it. So, is there any good place to start reading?
Thank you so much,
Daniel
[1] I experimented around with many B::???? modules,
tried to understand the B::Xref source code,
tired to figure out how to traverse the parse tree,
but could not find anything where to start, for example how to get this
tree at the first place...