Original Parser

version 1 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter - Identical

    [|Identical| decides whether or not two objects can be distinguished from each
    other by anything the player can type. If not, it returns |true|. (This
    routine is critical to the handling of plurals, and the list-writer
    requires it to be an equivalence relation between objects: but it is,
    because it is equivalent to $O_1\sim O_2$ if and only if $f(O_1) = f(O_2)$
    for some function $f$.)]

    To decide if (obj1 - an object) is not indistinguishable from (obj2 - an object):
        if obj1 is indistinguishable from obj2, no; otherwise yes.

    To decide if (obj1 - an object) is indistinguishable from (obj2 - an object) (this is Identical):
        if obj1 is obj2, yes;
        if obj1 is nothing or obj2 is nothing, no;
        if obj1 is a direction or obj2 is a direction, no;
        if the hidden parse name rule of obj1 is not currently blank or the hidden parse name rule of obj2 is not currently blank:
            if the hidden parse name rule of obj1 is not the hidden parse name rule of obj2, no;
            now What the parser's doing is identifying identical things;
            now Parser one is the obj1;
            now parser object two is the obj2;
            let the saved position be the parser's current word position;
            let the return value be the parse name rule of obj1 considered directly;
            now the parser's current word position is the saved position;
            if the return value is -1, yes;
            if the return value is -2, no;
        let find a difference be a truth state;
        repeat through the name list of obj1:
            we may find a difference;
            if the understood word element is listed in the name list of obj2, we no longer find a difference;
            if we find a difference, no;
        repeat through the name list of obj2:
            we may find a difference;
            if the understood word element is listed in the name list of obj1, we no longer find a difference;
            if we find a difference, no;
        yes.


    [ Identical o1 o2 p1 p2 n1 n2 i j flag;
    if (o1 == o2) rtrue; ! This should never happen, but to be on the safe side
    if (o1 == 0 || o2 == 0) rfalse; ! Similarly
    if (o1 ofclass K3_direction || o2 ofclass K3_direction) rfalse; ! Saves time

    ! What complicates things is that o1 or o2 might have a parsing routine,
    ! so the parser can't know from here whether they are or aren't the same.
    ! If they have different parsing routines, we simply assume they're
    ! different. If they have the same routine (which they probably got from
    ! a class definition) then the decision process is as follows:
    !
    ! the routine is called (with self being o1, not that it matters)
    ! with noun and second being set to o1 and o2, and action being set
    ! to the fake action TheSame. If it returns -1, they are found
    ! identical; if -2, different; and if >=0, then the usual method
    ! is used instead.

    if (o1.parse_name ~= 0 || o2.parse_name ~= 0) {
    if (o1.parse_name ~= o2.parse_name) rfalse;
    parser_action = ##TheSame; parser_one = o1; parser_two = o2;
    j = wn; i = RunRoutines(o1,parse_name); wn = j;
    if (i == -1) rtrue;
    if (i == -2) rfalse;
    }

    ! This is the default algorithm: do they have the same words in their
    ! "name" (i.e. property no. 1) properties. (Note that the following allows
    ! for repeated words and words in different orders.)

    p1 = o1.&1; n1 = (o1.#1)/WORDSIZE;
    p2 = o2.&1; n2 = (o2.#1)/WORDSIZE;

    ! for (i=0 : i<n1 : i++) { print (address) p1-->i, " "; } new_line;
    ! for (i=0 : i<n2 : i++) { print (address) p2-->i, " "; } new_line;

    for (i=0 : i<n1 : i++) {
    flag = 0;
    for (j=0 : j<n2 : j++)
    if (p1-->i == p2-->j) flag = 1;
    if (flag == 0) rfalse;
    }

    for (j=0 : j<n2 : j++) {
    flag = 0;
    for (i=0 : i<n1 : i++)
    if (p1-->i == p2-->j) flag = 1;
    if (flag == 0) rfalse;
    }

    ! print "Which are identical!^";
    rtrue;
    ]