bug in coco/r /r parser generator

"Pat Terry" <CSPT@giraffe.ru.ac.za>
Thu, 19 Aug 1993 16:55:30 GMT

          From comp.compilers

Related articles
bug in coco/r /r parser generator CSPT@giraffe.ru.ac.za (Pat Terry) (1993-08-19)
| List of all articles for this month |

Newsgroups: comp.compilers
From: "Pat Terry" <CSPT@giraffe.ru.ac.za>
Keywords: tools, errors, LL(1), parse, modula
Organization: Rhodes University
Date: Thu, 19 Aug 1993 16:55:30 GMT

I have just found another minor bug in coco/r, a LL(1) parser generator
generating Modula-2 sources:

Try the following silly grammar


          letter = "ABCDEFGHI" .

          label = letter { letter } .

          A = "DC" Mnemonic .
          Mnemonic = 'ACI' | 'DEC' | 'DS' | 'DC' | "ACI" | "AB".
      END A.

Notice the use of "DC" and 'DC' which really represent the same thing,
similarly "ACI" and 'ACI'. Coco/r versions up to 1.29 do not handle this

The bug is easily fixed by bootstrapping Coco with a corrected attribute
grammar. The fixes are outlined below

Add to the semantic declarations part of CR.ATG

        double: BOOLEAN;
        i: CARDINAL;
        IF CRT.ignoreCase THEN (* force uppercase *)
            FOR i := 1 TO len - 2 DO name[i] := CAP(name[i]) END
        double := FALSE;
        FOR i := 1 TO len - 2 DO (* search for interior " *)
            IF name[i] = '"' THEN double := TRUE END
        IF NOT double THEN (* force delimiters to be " quotes *)
            name[0] := '"'; name[len-1] := '"'
    END FixString;

Modify the following two productions to use FixString

Symbol <VAR name: CRT.Name; VAR kind: INTEGER> (.VAR
                                                                                                        i: CARDINAL;.)
    ( Ident <name> (.kind := ident.)
    | string (.CRS.GetName(CRS.pos, CRS.len, name);
                                                              kind := string;
                                                              FixString(name, CRS.len).)


NameDecl (.VAR
                                                                  name, str: CRT.Name;
                                                                  i : CARDINAL;.)
    = Ident <name> "="
        ( ident (.CRS.GetName(CRS.pos, CRS.len, str).)
            | string (.CRS.GetName(CRS.pos, CRS.len, str);
                                                  FixString(str, CRS.len).)
              ) (.CRT.NewName(name, str).)

Pat Terry, Computer Science, Rhodes University, GRAHAMSTOWN 6140, RSA
cspt@alpha.ru.ac.za or cspt@giraffe.ru.ac.za or pdterry@psg.com

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.