From: Sreedhar Reddy
Subject: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <7cc1d291.0309020349.307a1720@posting.google.com>
Hi,

Is there any function or set of steps to get the parse tree of given
code from the  lisp compiler?

thanks,

-Sreedhar Reddy
············@yahoo.com

From: Christopher C. Stacy
Subject: Re: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <usmnf5pq4.fsf@dtpq.com>
>>>>> On 2 Sep 2003 04:49:39 -0700, Sreedhar Reddy ("Sreedhar") writes:
 Sreedhar> Is there any function or set of steps to get the parse tree
 Sreedhar> of given code from the lisp compiler?

Not really.

In some implementations, the source code might be recoverable
under some circumstances.
From: Sreedhar Reddy
Subject: Re: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <7cc1d291.0309030402.594543c6@posting.google.com>
My goal is to displaying the given code (including the calls to
functions) in tree format.

For example:
        Let us suppose say there two function "saya" and "sayb", whose
definitions are:
          (defun saya()
                (print "a")
                (sayb))

           (defun sayb()
                (print "b"))

Let us suppose say user input is: (saya)

Then the output shall be a list (tree), may not be the same, but
similar:
        (saya (print "a" ("a")) (sayb (print "b" ("b"))))



The tree is:

saya+
    |
    |
    +(print "a")
    |     |  
    |     | 
    |     + ("b")
    |
    +(sayb)
        |
        |
        +(print "b")
              |
              |
              + ("b")


My Idea:
========
When we pass the lisp code to compiler(I mean when we compile the
code), the compiler constructs the parse tree.  My idea is to achieve
the above goal by accessing the compiler parse tree and output the
same (may be after manipulating the compiler parse tree to display in
desired form).
       
Are there any alternate ideas exist?

Is there any function or set of steps to access the compiler parse
tree?

Thanks,

Manikanti Sreedhar Reddy

······@dtpq.com (Christopher C. Stacy) wrote in message news:<·············@dtpq.com>...
> >>>>> On 2 Sep 2003 04:49:39 -0700, Sreedhar Reddy ("Sreedhar") writes:
>  Sreedhar> Is there any function or set of steps to get the parse tree
>  Sreedhar> of given code from the lisp compiler?
> 
> Not really.
> 
> In some implementations, the source code might be recoverable
> under some circumstances.
From: Christopher C. Stacy
Subject: Re: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <uu17tzu1n.fsf@dtpq.com>
>>>>> On 3 Sep 2003 05:02:45 -0700, Sreedhar Reddy ("Sreedhar") writes:
 Sreedhar> My goal is to displaying the given code (including the
 Sreedhar> calls to functions) in tree format.

You can use the DISASSEMBLE function to see what machine code
the compiler turned the program into.  It could have done all
kinds of things to the input program.   There is no way in the
language to get the internal compiler data structures that you 
are asking about.   You could ask the vendor of the particular
implementation that you're using if they have some clues about
how to go about doing what you're interested in.

You might start by looking at the source code for CLISP or for CMUCL,
which are two popular free open-source implementations of Common Lisp.
You could study how the compiler is implemented, and see if you can
rewrite part of it to do what you want.  I don't expect that what
you're asking for would necessarily be very easy.
It will, of course, not be portable to other Lisp implementations.
From: Christopher C. Stacy
Subject: Re: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <uptihztsc.fsf@dtpq.com>
Another idea would be to write your own program to do this.
The program is called a "code walker", and some implementations
may provide you with functions to help you write it.
Your program could then output the call tree you're interested in.

Consider, however, that in Lisp, functions can be passed around 
and called by other functions.  This is happenning at run-time,
not compile-time, so there is no way to create a call tree for
those function calls.

(defun mystery-1 (x)
  (funcall (read) x))

(defun mystery-2 (x)
  (let ((funs '(saya sayb)))
    (funcall (elt funs (random (length funs))) x)))
From: Sreedhar Reddy
Subject: Code Walker - Are there any code walkers which return the parse tree which has the call sequence with called functions instructions?
Date: 
Message-ID: <7cc1d291.0309032159.6e8f7653@posting.google.com>
Hi,

I have downloaded the Xerox's code walker from
ftp.cs.cmu.edu:user/ai/lang/lisp/code/codewalker/walk/.  Using this
able to walk the given form and not table get the call sequence, But I
am interested in total call sequence also.

Are there any other code walkers which return the parse tree which has
the call sequence with called functions instructions?(please see the
my previous mail, the last one)

I am able execute Xerox's code-walker using only walk-form function. 
Do you have any idea about how to use the nested-walk-form function?

thanks,

-Sreedhar Reddy

······@dtpq.com (Christopher C. Stacy) wrote in message news:<·············@dtpq.com>...
> Another idea would be to write your own program to do this.
> The program is called a "code walker", and some implementations
> may provide you with functions to help you write it.
> Your program could then output the call tree you're interested in.
> 
> Consider, however, that in Lisp, functions can be passed around 
> and called by other functions.  This is happenning at run-time,
> not compile-time, so there is no way to create a call tree for
> those function calls.
> 
> (defun mystery-1 (x)
>   (funcall (read) x))
> 
> (defun mystery-2 (x)
>   (let ((funs '(saya sayb)))
>     (funcall (elt funs (random (length funs))) x)))

>>From: Sreedhar Reddy (············@yahoo.com)
>>Subject: Re: Is there any way to get the parse tree from the
compiler
 
>>View this article only
>>Newsgroups: comp.lang.lisp
>>Date: 2003-09-03 05:02:46 PST

>>My goal is to displaying the given code (including the calls to
>>functions) in tree format.

>>For example:
>>        Let us suppose say there two function "saya" and "sayb",
whose
>>definitions are:
>>          (defun saya()
>>                (print "a")
>>                (sayb))

>>           (defun sayb()
>>                (print "b"))

>>Let us suppose say user input is: (saya)

>>Then the output shall be a list (tree), may not be the same, but
>>similar:
        (saya (print "a" ("a")) (sayb (print "b" ("b"))))



>>The tree is:

>>saya+
>>    |
>>    | +(print "a")
>>    |     |  
>>    |     | 
>>    |     + ("b")
>>    |
>>    +(sayb)
>>        |
>>        |
>>        +(print "b")
>>              |
>>              |
>>              + ("b")
>>

>>My Idea:
>>========
>>When we pass the lisp code to compiler(I mean when we compile the
>>code), the compiler constructs the parse tree.  My idea is to
achieve
>>the above goal by accessing the compiler parse tree and output the
>>same (may be after manipulating the compiler parse tree to display
in
>>desired form).
       
>>Are there any alternate ideas exist?

>>Is there any function or set of steps to access the compiler parse
>>tree?

>>Thanks,

>>Manikanti Sreedhar Reddy
From: Avi Blackmore
Subject: Re: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <7c1401ca.0309030244.13cf8917@posting.google.com>
············@yahoo.com (Sreedhar Reddy) wrote in message news:<····························@posting.google.com>...
> Hi,
> 
> Is there any function or set of steps to get the parse tree of given
> code from the  lisp compiler?
> 

(with-standard-disclaimer
   Yeah, the READ function.  Just READ the code in from the source
file, and you get what are basically parse trees: lists containing the
symbolic elements of the code.  You can do what you like with these
before passing them to COMPILE or EVAL.  It's usually more efficient,
I understand, to do such transforms with macros, however.  That's all
done at compile time, instead of run time, and saves a lot of
computation.  Still, it is nice that, if you need to, you can snarf up
parse trees at run time and play with them.)

Avi Blackmore
From: Christopher C. Stacy
Subject: Re: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <uy8x5zu8j.fsf@dtpq.com>
>>>>> On 3 Sep 2003 03:44:29 -0700, Avi Blackmore ("Avi") writes:

 Avi> ············@yahoo.com (Sreedhar Reddy) wrote in message news:<····························@posting.google.com>...
 >> Hi,
 >> 
 >> Is there any function or set of steps to get the parse tree of given
 >> code from the  lisp compiler?
 >> 

 Avi> (with-standard-disclaimer
 Avi>    Yeah, the READ function.  Just READ the code in from the source
 Avi> file, and you get what are basically parse trees: lists containing the
 Avi> symbolic elements of the code.

That's not coming from the compiuler, and it assumes that you have the
source code.  You might consider the source code to be the same as the
"parse tree", but that's not a very good definition, and I don't think
it's exactly what he was asking for.  For one thing, you may not have
any source code, or the code might be being generated dynamically so
that you can't get at it (without interfering with the programs that 
are generating it).

If he already had the input, he would probably not be asking, 
"Where can I get the input?"   I think he wanted to know how
to extract either the input source code or some related data
structure from the compiler from a function object ("given
code from the lisp compiler").

The language does not have that feature.  (Some implementations 
of the language might have extensions that let you do that, 
or something very close to that.  This is typically done by
saving a copy of the source as a property on the function.)
From: Sreedhar Reddy
Subject: Re: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <7cc1d291.0309032142.451a1875@posting.google.com>
Hi,

······@dtpq.com (Christopher C. Stacy) wrote in message news:<·············@dtpq.com>...
> >>>>> On 3 Sep 2003 03:44:29 -0700, Avi Blackmore ("Avi") writes:
> 
>  Avi> ············@yahoo.com (Sreedhar Reddy) wrote in message news:<····························@posting.google.com>...
>  >> Hi,
>  >> 
>  >> Is there any function or set of steps to get the parse tree of given
>  >> code from the  lisp compiler?
>  >> 
> 
>  Avi> (with-standard-disclaimer
>  Avi>    Yeah, the READ function.  Just READ the code in from the source
>  Avi> file, and you get what are basically parse trees: lists containing the
>  Avi> symbolic elements of the code.
> 
> That's not coming from the compiuler, and it assumes that you have the
> source code.  You might consider the source code to be the same as the
> "parse tree", but that's not a very good definition, and I don't think
> it's exactly what he was asking for.  For one thing, you may not have
> any source code, or the code might be being generated dynamically so
> that you can't get at it (without interfering with the programs that 
> are generating it).
> 
> If he already had the input, he would probably not be asking, 
> "Where can I get the input?"   I think he wanted to know how
> to extract either the input source code or some related data
> structure from the compiler from a function object ("given
> code from the lisp compiler").

The read function is, only generating the parse tree for each object,
but expected is something else.

for example:
       cl-user(1):(defun saya()
                     (print "a")
                     (sayb))
       cl-user(2): (defun sayb()
                      (print "b"))

       cl-user(3): (read)
                    (saya)
                  It returned "(SAYA)", but the expected out is the
call parse tree which has complete definitions of functions with
evalation branching.

For the above example the expected output for the user input "(saya)"
shall be:
                    (saya (print "a" ("a")) (sayb (print "b" ("b"))) 
                            
I think, I made clear about the problem?!       


> The language does not have that feature.  

Thanks for the information.

(Some implementations 
> of the language might have extensions that let you do that, 
> or something very close to that.  This is typically done by
> saving a copy of the source as a property on the function.)

I am using the Allegro CL 6.2, I did not encounter any such functions.
 I have to checke with my vendor.

I have written a small function to save the copy of the source as a
property on the function, but this way if we generate the "parse tree"
for the call sequence (with all instructions), the tree generatation
will be slow.

1) So, what I am trying here is to get the parse tree from the lisp
(compiler, ...), because it already has such tree.  I do not want the
tree to be in assembly code, the tree shall be in lisp code.

OR

2) construct the tree with some function and attach it to the
compiler/(or any other component) which parses the code.

Thanks,

-Sreedhar Reddy
From: Avi Blackmore
Subject: Re: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <7c1401ca.0309040317.511662f0@posting.google.com>
······@dtpq.com (Christopher C. Stacy) wrote in message news:<·············@dtpq.com>...

[snip snip]

> it's exactly what he was asking for.  For one thing, you may not have
> any source code, or the code might be being generated dynamically so
> that you can't get at it (without interfering with the programs that 
> are generating it).

    Ahh, right, sorry.  I stand corrected.  Well, okay, sit.  

[snicker snack]

> The language does not have that feature.  (Some implementations 
> of the language might have extensions that let you do that, 
> or something very close to that.  This is typically done by
> saving a copy of the source as a property on the function.)

    Oh, yes, this was in that other thread, where he was asking about
how to save a copy of the function source, and someone (can't remember
who offhand) suggested sticking the source onto the property list, no?
 I suppose that'd do a pretty decent job for any code written with
that modified  DEFUN, but not in the general case.  Hmmm...

    Anyway, probably best that I shut up now and not make myself look
even dumber than I've already done.  :-(

Avi Blackmore
From: Sreedhar Reddy
Subject: Re: Is there any way to get the parse tree from the compiler
Date: 
Message-ID: <7cc1d291.0309092235.7bb21692@posting.google.com>
Hi

Certainly we can always talk about the problem and find the good answer.

Please smile.

thanks,

-Sreedhar Reddy

········@cableone.net (Avi Blackmore) wrote in message news:<····························@posting.google.com>...
> ······@dtpq.com (Christopher C. Stacy) wrote in message news:<·············@dtpq.com>...
> 
> [snip snip]
> 
> > it's exactly what he was asking for.  For one thing, you may not have
> > any source code, or the code might be being generated dynamically so
> > that you can't get at it (without interfering with the programs that 
> > are generating it).
> 
>     Ahh, right, sorry.  I stand corrected.  Well, okay, sit.  
> 
> [snicker snack]
> 
> > The language does not have that feature.  (Some implementations 
> > of the language might have extensions that let you do that, 
> > or something very close to that.  This is typically done by
> > saving a copy of the source as a property on the function.)
> 
>     Oh, yes, this was in that other thread, where he was asking about
> how to save a copy of the function source, and someone (can't remember
> who offhand) suggested sticking the source onto the property list, no?
>  I suppose that'd do a pretty decent job for any code written with
> that modified  DEFUN, but not in the general case.  Hmmm...
> 
>     Anyway, probably best that I shut up now and not make myself look
> even dumber than I've already done.  :-(
> 
> Avi Blackmore