Coco again 
Author Message
 Coco again

Hello,
I made a trivial example regarding the Problem I have with white
spaces in Coco grammars. Included is a Test Grammar (together with
trivial Parser Module) and a file, which is not parsed until the end,
but only until the first string containing a string is encountered.

I am almost sure that this is due to erroneous thinking on my side,
but I would also ask if someone would be so as to check the outcome of
a test with the included grammar and test file on their systems.

Regards,
        Harald
<><><><>File Bl.ATG:
COMPILER Bl

IMPORT Oberon, Texts;

VAR
w: Texts.Writer;
string: ARRAY 80 OF CHAR;
c: LONGINT;

PROCEDURE Err(nr: INTEGER);
BEGIN BlS.Error(100 + nr, BlS.pos) END Err;

CHARACTERS
tab = CHR(9).
eol = CHR(13).
incspc = ANY - eol.

TOKENS
Qt = '"' {incspc} '"'.

IGNORE eol

PRODUCTIONS

Bl
        =
                                (. Texts.OpenWriter(w) .)
                                (.  c := 0 .)
        DQ {DQ}
                                (. Texts.WriteInt(w, c, 4) .)
                                (. Texts.WriteLn(w) .)
                                (. Texts.Append(Oberon.Log, w.buf) .)

        .

DQ
        =COMPILER Bl

IMPORT Oberon, Texts;

VAR
w: Texts.Writer;
string: ARRAY 80 OF CHAR;
c: LONGINT;

PROCEDURE Err(nr: INTEGER);
BEGIN BlS.Error(100 + nr, BlS.pos) END Err;

CHARACTERS
tab = CHR(9).
eol = CHR(13).
incspc = ANY - eol.

TOKENS
Qt = '"' {incspc} '"'.

IGNORE eol

PRODUCTIONS

Bl
        =
                                (. Texts.OpenWriter(w) .)
                                (.  c := 0 .)
        DQ {DQ}
                                (. Texts.WriteInt(w, c, 4) .)
                                (. Texts.WriteLn(w) .)
                                (. Texts.Append(Oberon.Log, w.buf) .)

        .

DQ
        =
        Qt              (. INC(c); Texts.WriteString(w, "c ") .)
                                (. BlS.GetName(BlS.pos, BlS.len, string) .)
                                (. Texts.WriteString(w, string) .)
                                (. Texts.WriteLn(w) .).
END Bl.

Coco.Compile Bl.ATG ~
System.Fre
        Qt              (. INC(c); Texts.WriteString(w, "c ") .)
                                (. BlS.GetName(BlS.pos, BlS.len, string) .)
                                (. Texts.WriteString(w, string) .)
                                (. Texts.WriteLn(w) .).
END Bl.

Coco.Compile Bl.ATG ~
System.Free Bl BlP BlS ~
Builder.Compile BlP.Mod BlS.Mod Bl.Mod ~
Bl.Compile BlTest.Text~

<><><><><>File Bl.Mod
MODULE Bl;      (** HW  **)

IMPORT
                Oberon, Out, Texts, BlS, BlP;

CONST minErrDist = 8;

VAR w: Texts.Writer; lastErrPos: LONGINT;

PROCEDURE Error (n: INTEGER; pos: LONGINT);

        PROCEDURE Msg (s: ARRAY OF CHAR);
        BEGIN Texts.WriteString(w, s); Texts.WriteLn(w);
        END Msg;

BEGIN
        INC(BlS.errors);
        IF pos < lastErrPos + minErrDist THEN lastErrPos := pos; RETURN END ;
        lastErrPos := pos;
        Texts.WriteInt(w, pos, 4);
        Texts.WriteString(w, ": ");
        Texts.WriteString(w, "error ");
        Texts.WriteInt(w, n, 0);
        Texts.WriteLn(w)
 END Error;

PROCEDURE Options(VAR s: Texts.Scanner);
        VAR i: INTEGER;
BEGIN
        IF s.nextCh = Oberon.OptionChar THEN Texts.Scan(s); Texts.Scan(s);
                IF s.class = Texts.Name THEN i := 0;
                        WHILE s.s[i] # 0X DO
                                INC(i);
                        END
                END
        END;
END Options;

PROCEDURE Compile*;
        VAR s: Texts.Scanner; src, t: Texts.Text;
                pos, beg, end, time: LONGINT; i: INTEGER;
BEGIN
        Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
        src := NIL; pos := 0;
        IF (s.class = Texts.Char) & (s.c = "^") THEN
                Oberon.GetSelection(t, beg, end, time);
                IF time >=0 THEN Texts.OpenScanner(s,t,beg); Texts.Scan(s) END
        END;
        IF s.class = Texts.Name THEN
                NEW(src); Texts.Open(src, s.s)
        ELSIF (s.class = Texts.Char) & (s.c = "*") THEN
                src:= Oberon.MarkedText()

                Oberon.GetSelection(t, beg, end, time);
                IF time >=0 THEN src := t; pos := beg; s.s := " " END
        END;

<><><><>File BlTest.Text
""
"1"
"   "
"sdf ds f gd"
"sdfgsdfgljh"
"sdfgdfglkjh"

--
Harald Wagener                        Uni Bremen, Fb3 -- Informatik

Tel: +49 421 2184216                         Mobil: +49 174 7530012



Sun, 09 Mar 2003 03:00:00 GMT  
 Coco again

Quote:

> Hello,
> I made a trivial example regarding the Problem I have with white
> spaces in Coco grammars. Included is a Test Grammar (together with
> trivial Parser Module) and a file, which is not parsed until the end,
> but only until the first string containing a string is encountered.

> CHARACTERS
> tab = CHR(9).
> eol = CHR(13).
> incspc = ANY - eol.

> TOKENS
> Qt = '"' {incspc} '"'.

The character set incspc includes the character '"', so it
absorbs the closing quote at the end of a Qt token.
Maybe your definition of incspc should be something like

     incspc = ANY - '"'.

-Greg



Sun, 09 Mar 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. COCO/P: Looking for COCO Applications

2. Scheme vs ML again and again and again and again

3. Scheme vs ML again and again and again and again

4. APL and J (again and again) (long)

5. APL and J (again and again)

6. 'SQL Server Login': Again, again, ...

7. static vs. dynamic typing (again, again)

8. Scheme vs ML again and again

9. All in EXE file AGAIN AGAIN

10. trees again and again

11. Re-inventing hot water again and again

12. tcltest processes subdirectory again and again - Why?

 

 
Powered by phpBB® Forum Software