Related articles |
---|
bug in coco/r /r parser generator CSPT@giraffe.ru.ac.za (Pat Terry) (1993-08-19) |
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
COMPILER A
CHARACTERS
letter = "ABCDEFGHI" .
TOKENS
label = letter { letter } .
PRODUCTIONS
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
correctly.
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
PROCEDURE FixString (VAR name: ARRAY OF CHAR; len : CARDINAL);
VAR
double: BOOLEAN;
i: CARDINAL;
BEGIN
IF CRT.ignoreCase THEN (* force uppercase *)
FOR i := 1 TO len - 2 DO name[i] := CAP(name[i]) END
END;
double := FALSE;
FOR i := 1 TO len - 2 DO (* search for interior " *)
IF name[i] = '"' THEN double := TRUE END
END;
IF NOT double THEN (* force delimiters to be " quotes *)
name[0] := '"'; name[len-1] := '"'
END;
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
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.