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

Martin Rubey martin.rubey at univie.ac.at
Wed Oct 25 17:04:58 EDT 2006


Dear Christian, Gaby,

Please excuse the very long mail. I didn't have the time to create a self
contained, short program, although it should be done, probably. Excuse me,
please.

I did something rather simple with a result that surprised me a little in its
simplicity. I modified grammar to output some memory locations. As I learned
last week,

Thing pretend Pointer

gives me the memory location of Thing. Here is the modified grammar function:

-------------------------------------------------------------------------------

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];
        
	import from String, Character, TextWriter;
        import from Pointer, Generator Pointer, List Pointer;
	stderr << "starting grammar " << p << newline;        
        stderr << "res is " <<         
                   [r pretend Pointer for r in res] << newline;                        
        
        E(i: MachineInteger): CC == {
                stderr << "before evalution" << newline;        
                evaluate(parse(p.i), res) add {
                        TRACEINSTANTIATION;
                        valuation(): Integer == 1
                }
        }
        
        for i in 1..#p repeat {
	        stderr << "define check " << i << newline;                        
                check :=  E(i);
                stderr << "res is still " <<         
                          [r pretend Pointer for r in res] << newline;
	        stderr << "check is     "  << 
                          check pretend Pointer << newline;                                
                res.i := check;
        }
	stderr << "finished" << newline;                        
        stderr << "res is now " <<         
                  [r pretend Pointer for r in res] << newline;                
        res;
}

-------------------------------------------------------------------------------

I also made certain domains print out a message

Domain Instatiation: name of domain

when their "add {...}" - body get's evaluated. Furthermore, I made "evaluate"
print out the memory locations of the second argument it receives, which is
"res".

Below is the result of grammar(["Union(Atom, Cross(Self1, Self1))"]).  Comments
I added begin with --.

-------------------------------------------------------------------------------

starting grammar [Union(Atom, Cross(Self1, Self1))]
res is [0x83d9850]          -- this is the mem.loc. of Atom
define check 1              -- we are already in the loop at the end of the 
                            -- grammar-function!
before evalution            -- E(1) was called
                            -- but note that evaluate is not yet called!
res is still [0x83d9850]    
check is     0x83f87f8
finished
res is now [0x83f87f8]      -- we are about to leave grammar already!

-------------------------------------------------------------------------------

Thus, evaluate was not even called so far, as suspected by Christian.  Now we
use the domain by calling one of its functions.

-------------------------------------------------------------------------------

in evaluate
ExpressionTree is (Union "Atom" (Cross "Self1" "Self1"))
selfList is    [0x83f87f8]  -- the parameter is not the original one,
                            -- which was Atom. it is res itself, now.
in evaluate
ExpressionTree is "Atom"
selfList is    [0x83f87f8]
in evaluate
ExpressionTree is (Cross "Self1" "Self1")
selfList is    [0x83f87f8]
in evaluate
ExpressionTree is "Self1"
selfList is    [0x83f87f8]
in evaluate
ExpressionTree is "Self1"
selfList is    [0x83f87f8]
Domain Instatiation: E()
Domain Instatiation: CombinatorialUnion(Atom,CombinatorialCross(E(),E()))
Domain Instatiation: CombinatorialCross(E(),E())

-------------------------------------------------------------------------------

Thus, I guess 100/100 for Christian A. It seems that a function returning a
domain is evaluated only when the domain is actually used. 

Christian, what do you think?




For those who like following such traces, here is another one:

-------------------------------------------------------------------------------

starting grammar [Union(Atom, Cross(Self2,Self2)),Union(Atom, Cross(Self1,Self1,Self1))]
res is    [0x83d9850,0x83d9850]
define check 1
before evalution
res is still [0x83d9850,0x83d9850]
check is     0x83fab60
define check 2
before evalution
res is still [0x83fab60,0x83d9850] -- well, no, res.1 has changed, of course
check is     0x83fac88
res is now [0x83fab60,0x83fac88]

-------------------------------------------------------------------------------

now we are going to use Self1:

-------------------------------------------------------------------------------

Domain Instatiation: CombinatorialUnion(Atom,CombinatorialCross(Tree3,Tree3))
Domain Instatiation: CombinatorialCross(Tree3,Tree3)
Domain Instatiation: CombinatorialUnion(Atom,CombinatorialCross(CombinatorialCross(Tree2,Tree2),Tree2))
Domain Instatiation: CombinatorialCross(CombinatorialCross(Tree2,Tree2),Tree2)
Domain Instatiation: CombinatorialCross(Tree2,Tree2)
in evaluate
ExpressionTree is (Union "Atom" (Cross "Self2" "Self2"))
selfList is    [0x83fab60,0x83fac88]
in evaluate
ExpressionTree is "Atom"
selfList is    [0x83fab60,0x83fac88]
in evaluate
ExpressionTree is (Cross "Self2" "Self2")
selfList is    [0x83fab60,0x83fac88]
in evaluate
ExpressionTree is "Self2"
selfList is    [0x83fab60,0x83fac88]
in evaluate
ExpressionTree is "Self2"
selfList is    [0x83fab60,0x83fac88]
Domain Instatiation: E()
Domain Instatiation: CombinatorialUnion(Atom,CombinatorialCross(E(),E()))
Domain Instatiation: CombinatorialCross(E(),E())
in evaluate
ExpressionTree is (Union "Atom" (Cross "Self1" "Self1" "Self1"))
selfList is    [0x83fab60,0x83fac88]
in evaluate
ExpressionTree is "Atom"
selfList is    [0x83fab60,0x83fac88]
in evaluate
ExpressionTree is (Cross "Self1" "Self1" "Self1")
selfList is    [0x83fab60,0x83fac88]
in evaluate
ExpressionTree is "Self1"
selfList is    [0x83fab60,0x83fac88]
in evaluate
ExpressionTree is "Self1"
selfList is    [0x83fab60,0x83fac88]
in evaluate
ExpressionTree is "Self1"
selfList is    [0x83fab60,0x83fac88]
Domain Instatiation: E()
Domain Instatiation: CombinatorialUnion(Atom,CombinatorialCross(E(),CombinatorialCross(E(),E())))
Domain Instatiation: CombinatorialCross(E(),CombinatorialCross(E(),E()))
Domain Instatiation: CombinatorialCross(E(),E())

-------------------------------------------------------------------------------

All the best, 

Martin




More information about the Aldor-l mailing list