Executing AST

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Executing AST

NorbertHartl
Hi,

I'm playing a little with parsing and executing smalltalk
expressions.

I have a tree from

RBParser parseExpression: ('3 + 4' readStream)

How can I execute the expression? Do I have to generate code
first or is this tree somehow executable?

thanks,

Norbert


Reply | Threaded
Open this post in threaded view
|

Re: Executing AST

Philippe Marschall
2007/7/8, Norbert Hartl <[hidden email]>:

> Hi,
>
> I'm playing a little with parsing and executing smalltalk
> expressions.
>
> I have a tree from
>
> RBParser parseExpression: ('3 + 4' readStream)
>
> How can I execute the expression? Do I have to generate code
> first or is this tree somehow executable?

The Persephone package on SqueakSource includes an interpreter that
works on RB AST nodes. It even has support for primitives.

Cheers
Philippe

> thanks,
>
> Norbert
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Executing AST

Bergel, Alexandre
In reply to this post by NorbertHartl
Hi Norbert,

I am currently working on a squeak interpreter.
It is available on Squeaksource. If you want to try it, load Perseus,  
and SmalltalkP
http://www.squeaksource.com/Perseus
http://www.squeaksource.com/SmalltalkInPerseus

Have a look at the test.

This is a very preliminary work, and the design will have to be  
redone, but the essence is there.

Let me know about how far you went with it :-)

Alexandre


On 8 Jul 2007, at 14:31, Norbert Hartl wrote:

> Hi,
>
> I'm playing a little with parsing and executing smalltalk
> expressions.
>
> I have a tree from
>
> RBParser parseExpression: ('3 + 4' readStream)
>
> How can I execute the expression? Do I have to generate code
> first or is this tree somehow executable?
>
> thanks,
>
> Norbert
>
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: Executing AST

NorbertHartl
On Sun, 2007-07-08 at 18:13 +0200, Bergel, Alexandre wrote:

> Hi Norbert,
>
> I am currently working on a squeak interpreter.
> It is available on Squeaksource. If you want to try it, load Perseus,  
> and SmalltalkP
> http://www.squeaksource.com/Perseus
> http://www.squeaksource.com/SmalltalkInPerseus
>
> Have a look at the test.
>
> This is a very preliminary work, and the design will have to be  
> redone, but the essence is there.
>
> Let me know about how far you went with it :-)
>
Don't wait for it :) I was just looking for something that lets
me produce code and parse and execute it afterwards. I struggle
a lot using Glorp and therefor being bound the some degree to
SQL semantics. My hope was that storing code in the database and
executing it on retrieval could solve a lot of problems. I still
think this is feasible. But if the setup is too complicated (I
don't have much time) and is not mature I can't rely on it.

I was not very clear in my intention. I was more looking for an
easy way to serialize/deserialize objects. I'll do it for now
using a textual interpretation of

self class asString,':',self id

If I find some time I'll have look at it because this is a very
interesting topic.


thanks,

Norbert


Reply | Threaded
Open this post in threaded view
|

Re: Executing AST

Alan Kay
Why not just use the fact that Smalltalk can compile and execute any
string on the fly?

Also take a look at the many ways in Smalltalk to serialize and
deserialize objects. Some of the most recent has been done by Yoshiki Ohshima.

Cheers,

Alan

----------

At 02:45 PM 7/8/2007, Norbert Hartl wrote:

>On Sun, 2007-07-08 at 18:13 +0200, Bergel, Alexandre wrote:
> > Hi Norbert,
> >
> > I am currently working on a squeak interpreter.
> > It is available on Squeaksource. If you want to try it, load Perseus,
> > and SmalltalkP
> > http://www.squeaksource.com/Perseus
> > http://www.squeaksource.com/SmalltalkInPerseus
> >
> > Have a look at the test.
> >
> > This is a very preliminary work, and the design will have to be
> > redone, but the essence is there.
> >
> > Let me know about how far you went with it :-)
> >
>Don't wait for it :) I was just looking for something that lets
>me produce code and parse and execute it afterwards. I struggle
>a lot using Glorp and therefor being bound the some degree to
>SQL semantics. My hope was that storing code in the database and
>executing it on retrieval could solve a lot of problems. I still
>think this is feasible. But if the setup is too complicated (I
>don't have much time) and is not mature I can't rely on it.
>
>I was not very clear in my intention. I was more looking for an
>easy way to serialize/deserialize objects. I'll do it for now
>using a textual interpretation of
>
>self class asString,':',self id
>
>If I find some time I'll have look at it because this is a very
>interesting topic.
>
>
>thanks,
>
>Norbert


Reply | Threaded
Open this post in threaded view
|

Re: Executing AST

NorbertHartl
On Sun, 2007-07-08 at 17:24 -0700, Alan Kay wrote:
> Why not just use the fact that Smalltalk can compile and execute any
> string on the fly?
>
Yes I recognized this after just "proving" my first idea.  I have
to take one or two other approaches as I don't like my current one.

> Also take a look at the many ways in Smalltalk to serialize and
> deserialize objects. Some of the most recent has been done by Yoshiki Ohshima.
>
I must confess I was too fast and too lazy (as often )while writing my
postings. I don't need serialization/deserialization exactly. I only
have objects which are persistent in a database and therefor have an
id (could be any lookup key). I just need something to dump a derivate
of the object (recognizing the object and the lookup key) and that is
able to retrieve again at a later point. The harder point is that it
would be useful to produce such derivates from a structure like a
collection or anything else. I don't know of any Smalltalk solution
which helps me on that path, do you?

Btw. serialization. I'm already an user of SIXX (but it is not from
yoshiki, right?) and this just a wonderful tool. For the current
purpose it may be to heavy weight but I'll think again about it.

What did you mean by most recent work done by yoshiki?

Norbert




Reply | Threaded
Open this post in threaded view
|

Re: Executing AST

Tapple Gao
On Mon, Jul 09, 2007 at 08:06:11AM +0200, Norbert Hartl wrote:

> On Sun, 2007-07-08 at 17:24 -0700, Alan Kay wrote:
> > Why not just use the fact that Smalltalk can compile and execute any
> > string on the fly?
> >
> Yes I recognized this after just "proving" my first idea.  I have
> to take one or two other approaches as I don't like my current one.
>
> > Also take a look at the many ways in Smalltalk to serialize and
> > deserialize objects. Some of the most recent has been done by Yoshiki Ohshima.
> >
> I must confess I was too fast and too lazy (as often )while writing my
> postings. I don't need serialization/deserialization exactly. I only
> have objects which are persistent in a database and therefor have an
> id (could be any lookup key). I just need something to dump a derivate
> of the object (recognizing the object and the lookup key) and that is
> able to retrieve again at a later point. The harder point is that it
> would be useful to produce such derivates from a structure like a
> collection or anything else. I don't know of any Smalltalk solution
> which helps me on that path, do you?

Well, the smalltalk image is a persistent database of code and
objects, and one can store any code or objects in it and use
or modify them while the system is running. I bet you are
already using it.

--
Matthew Fulmer -- http://mtfulmer.wordpress.com/
Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808

Reply | Threaded
Open this post in threaded view
|

Re: Executing AST

NorbertHartl
On Sun, 2007-07-08 at 23:12 -0700, Matthew Fulmer wrote:

> On Mon, Jul 09, 2007 at 08:06:11AM +0200, Norbert Hartl wrote:
> > On Sun, 2007-07-08 at 17:24 -0700, Alan Kay wrote:
> > > Why not just use the fact that Smalltalk can compile and execute any
> > > string on the fly?
> > >
> > Yes I recognized this after just "proving" my first idea.  I have
> > to take one or two other approaches as I don't like my current one.
> >
> > > Also take a look at the many ways in Smalltalk to serialize and
> > > deserialize objects. Some of the most recent has been done by Yoshiki Ohshima.
> > >
> > I must confess I was too fast and too lazy (as often )while writing my
> > postings. I don't need serialization/deserialization exactly. I only
> > have objects which are persistent in a database and therefor have an
> > id (could be any lookup key). I just need something to dump a derivate
> > of the object (recognizing the object and the lookup key) and that is
> > able to retrieve again at a later point. The harder point is that it
> > would be useful to produce such derivates from a structure like a
> > collection or anything else. I don't know of any Smalltalk solution
> > which helps me on that path, do you?
>
> Well, the smalltalk image is a persistent database of code and
> objects, and one can store any code or objects in it and use
> or modify them while the system is running. I bet you are
> already using it.
>
Yes, but it need to access this particular piece of information from
several images. So I have to persist it outside the image and this
opens the problem for me. Using just the image wouldn't have me brought
to my very first problem ;))

Norbert


Reply | Threaded
Open this post in threaded view
|

Re: Executing AST

jgfoster
Norbert Hartl wrote:
> Yes, but it need to access this particular piece of information from
> several images. So I have to persist it outside the image and this
> opens the problem for me. Using just the image wouldn't have me brought
> to my very first problem ;))
Do you need to access the same data "from several images," or would it
be adequate to access the same data from several Smalltalk VMs running
against the same image? Have you considered GemStone (see
http://seaside.gemstone.com/ for an announcement of a no-cost edition)?

James Foster
GemStone Systems, Inc.

Reply | Threaded
Open this post in threaded view
|

Persephone

Bergel, Alexandre
In reply to this post by Philippe Marschall
Hi Philippe,

Was wondering why an interpreter is needed in Persephone?

Alexandre


On 8 Jul 2007, at 17:30, Philippe Marschall wrote:

> 2007/7/8, Norbert Hartl <[hidden email]>:
>> Hi,
>>
>> I'm playing a little with parsing and executing smalltalk
>> expressions.
>>
>> I have a tree from
>>
>> RBParser parseExpression: ('3 + 4' readStream)
>>
>> How can I execute the expression? Do I have to generate code
>> first or is this tree somehow executable?
>
> The Persephone package on SqueakSource includes an interpreter that
> works on RB AST nodes. It even has support for primitives.
>
> Cheers
> Philippe
>
>> thanks,
>>
>> Norbert
>>
>>
>>
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: Persephone

Philippe Marschall
2007/7/10, Bergel, Alexandre <[hidden email]>:
> Hi Philippe,
>
> Was wondering why an interpreter is needed in Persephone?

Easily hooking into the execution at a high level of abstraction.

Philippe

> Alexandre
>
>
> On 8 Jul 2007, at 17:30, Philippe Marschall wrote:
>
> > 2007/7/8, Norbert Hartl <[hidden email]>:
> >> Hi,
> >>
> >> I'm playing a little with parsing and executing smalltalk
> >> expressions.
> >>
> >> I have a tree from
> >>
> >> RBParser parseExpression: ('3 + 4' readStream)
> >>
> >> How can I execute the expression? Do I have to generate code
> >> first or is this tree somehow executable?
> >
> > The Persephone package on SqueakSource includes an interpreter that
> > works on RB AST nodes. It even has support for primitives.
> >
> > Cheers
> > Philippe
> >
> >> thanks,
> >>
> >> Norbert
> >>
> >>
> >>
> >
>
> --
> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
> Alexandre Bergel  http://www.bergel.eu
> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Executing AST

Mark Miller
In reply to this post by NorbertHartl
Norbert Hartl wrote on 2007-07-08:

"I must confess I was too fast and too lazy (as often )while writing my
postings. I don't need serialization/deserialization exactly. I only
have objects which are persistent in a database and therefor have an
id (could be any lookup key). I just need something to dump a derivate
of the object (recognizing the object and the lookup key) and that is
able to retrieve again at a later point. The harder point is that it
would be useful to produce such derivates from a structure like a
collection or anything else. I don't know of any Smalltalk solution
which helps me on that path, do you?"

Hi Norbert.

Without more information I think we're just "stabbing in the dark" at an answer for you. Could you give an example of what you want to do?

>From what I've surmised so far it sounds like you'd like to store expressions in the database, and retrieve them back out again. What I imagine you'd also like to do is take database data associated with the expressions and perhaps do some sort of substitution into your expressions, and then evaluate them at some point. Does this sound right?

I'm just wondering if you're making it more complicated than it needs to be, to accomplish what you want.

As Alan Kay indicated earlier, you can evaluate expressions on the fly, like:

| block blockInString |
blockInString := '[Transcript show: ''Hello world''; cr]'.
block := Compiler evaluate: blockInString for: BlockClosure logged: false.
block value

If you keep your expressions inside blocks then you can always just say "for: BlockClosure" in the evaluation step to keep it simple.

---Mark
[hidden email]