Original Parser

version 1 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter - BestGuess

    [|BestGuess| makes the best guess it can out of the match list, assuming that
    everything in the match list is textually as good as everything else;
    however it ignores items marked as $-1$, and so marks anything it chooses.
    It returns $-1$ if there are no possible choices.]

    To decide which object is the best guess (this is BestGuess):
        let the best be at the 0th position;
        let the best score so far be -1;
        repeat through the match score list of size the number of objects in the match list:
            if the match list element is not the used-up object:
                if the number element > the best score so far:
                    now the best score so far is the number element;
                    now the best is at the chosen position;
        if trace 4, say "[if the best score so far is less than zero] Best guess ran out of choices[line break][otherwise] Best guess [the best element of the match list] ([best element of the match list as a debugging number])[line break]";
        if the best score so far is less than zero, decide on the used-up object;
        let the best object be the best element of the match list;
        change the best element of the match list to the used-up object;
        decide on the best object.

    [ BestGuess earliest its_score best i;
    earliest = 0; best = -1;
    for (i=0 : i<number_matched : i++) {
    if (match_list-->i >= 0) {
    its_score = match_scores-->i;
    if (its_score > best) { best = its_score; earliest = i; }
    }
    }
    #Ifdef DEBUG;
    if (parser_trace >= 4)
    if (best < 0) print " Best guess ran out of choices^";
    else print " Best guess ", (the) match_list-->earliest,
    " (", match_list-->earliest, ")^";
    #Endif; ! DEBUG
    if (best < 0) return -1;
    i = match_list-->earliest;
    match_list-->earliest = -1;
    return i;
    ]