[Aldor-l] Should this "parser" work?

Martin Rubey martin.rubey at univie.ac.at
Fri Oct 20 13:01:49 EDT 2006


Dear Christian,

"Christian Aistleitner" <tmgisi at gmx.at> writes:

> > -------------------------------------------------------------------------------
> >
> > parse(s: String): ExpressionTree == {
> > ...
> > }
> >
> > -- evaluate basically replaces expressions "Self1", "Self2", etc.  appearing
> > in
> > -- t with the corresponding elements of selfList
> > evaluate(
> >     t: ExpressionTree,
> >     selfList: List CombinatorialClass
> > ): CombinatorialClass == {
> > ...
> > }
> >
> > grammar(p: List String): List CombinatorialClass == {
> >         macro CC == CombinatorialClass;
> >         import from MachineInteger, List CC;
> >         A: CC == Atom;
> >         res: List CC := [A for x in p];
> >
> >         E(i: MachineInteger): CC == evaluate(parse(p.i), res) add;
> >
> >         for i in 1..#p repeat res.i := E(i);
> >         res;
> > }
> >
> > -------------------------------------------------------------------------------
> >
> > Consider for example the effect of
> >
> > grammar(["Union(Atom, Cross(Self1, Self1))"])
> >
> > * res is initialized to [b] with "b" being an instance of the
> >   CombinatorialClass Atom.
> 
> I am not to sure about whether or not “"b" being an instance of [...]  Atom”
> is correct. As your situation is quite tricky, and you seem to look at the
> whole thing from a different angle than I am, can you explain to me, what
> happens internally, so that your code is working?
> 
>  From my point of view, your code looks like this in memory (I use the format
> Adress: Data. All references to other entities are explicitely written
> down). 

Hm, I find these “virtual memory locations” difficult to follow, but I'll try.
Let's stick to the example
grammar(["Union(Atom,Cross(Self1,Self1))"]). However, I have difficulties
following your setup:

> It translates
> 
> Definition of CombinatorialClass:
> 00001000: [...]
> 
> Definition of List( CombinatorialClass ):
> 00002000: [...] 00001000 [...]
> 
> Definition of Atom:
> 00003000: [...]
> 
> Definition of A:
> 00004000: [...] 00003000 [...]
> 
> Definition of res:
> 00005000:  00003000 00005010
> 00005010:  00003000 00000000

but res depends also on List(CombinatorialClass), doesn't it?


I suggest the following scheme. The situation before E(1) is called is

memory loc | Name     | associated functions and data

01           Atom
02           CC
03           List(CC) 
10           A          CC, Atom
20           res        List(CC), 21           # 21 is the mem. loc. of the
                                               # first element of res
21                      10                     # doesn't have a name
-------------------------------------------------------------------------------
Now E(1) is called. Suppose the result is stored in mem. loc. 31

memory loc | Name     | associated functions and data
31                      CC, Union(Atom, Cross(21, 21))

-------------------------------------------------------------------------------
Finally we assign res.1 a new value. We then have

memory loc | Name     | associated functions and data

01           Atom
02           CC
03           List(CC) 
10           A          CC, Atom
20           res        List(CC), 21           # 21 is the mem. loc. of the
                                               # first element of res
21                      31                     # doesn't have a name

31                      CC, Union(Atom, Cross(21, 21))

I.e., the only thing that changes is the value at mem. loc. 21.



Is this what you had in mind?

Thanks for your patience,

Martin





More information about the Aldor-l mailing list