Testing output
This program is basically a translation of your Pascal-program, Manfred, and I tried to be as true as possible to the output (except for my error messages, they might be a bit sloppy, I haven’t checked). So I thought I’d try it on the grammar on your web-page. But first, some errors:
.
Error: Seen . when non-terminal expected.
(.
Error: Seen ( when non-terminal expected.
Error: Seen . when non-terminal expected.
ja/.
Error: Seen / when This char is illegal.
Error: Seen . when non-terminal expected.
ja=' .
Error: Seen when no white space as terminal
Error: Seen . when non-terminal expected.
ja='..
Error: Seen . when no . as terminal
Error: Seen . when non-terminal expected.
ja=si|yes.
Undefined non-terminal si . Panicking.
FORMULA = EXPRESSION { ('> | '=) FORMULA };
EXPRESSION = TERM [ 'v TERM ];
TERM = FACTOR [ '& FACTOR ];
FACTOR = PREDICATE [ CONSTANT | VARIABLE ]
| '- FACTOR
| '( FORMULA ')
| '( ('A | 'E) VARIABLE ') FACTOR;
PREDICATE = 'A | 'B | 'C | 'D | 'E | 'F | 'G | 'H | 'I
| 'J | 'K | 'L | 'M | 'N | 'O | 'P | 'Q | 'R
| 'S | 'T | 'U | 'V | 'W | 'X | 'Y | 'Z;
CONSTANT = 'a | 'b | 'c | 'd | 'e | 'f | 'g;
VARIABLE = 'u | 'v | 'w | 'x | 'y | 'z.
P v (Q > -(R & S)).
... well-formed -
1: P v(Q>-(R&S))
2: Pv(Q>-(R&S))
3: Pv (Q>-(R&S))
Gb v Hcd > Iabc.
... well-formed -
1: G bvHcd>Iabc
2: Gb vHcd>Iabc
3: GbvH cd>Iabc
4: GbvHc d>Iabc
5: GbvHcd >Iabc
6: GbvHcd>I abc
7: GbvHcd>Ia bc
8: GbvHcd>Iab c
9: GbvHcd>Iabc
10: Gbv Hcd>Iabc
(Ax)(Fx v Gx).
... well-formed -
1: (Ax) (FxvGx)
2: (Ax)(FxvGx)
P = Q.
... well-formed -
1: P =Q
2: P=Q
(Ab)(Cd).
... well-formed -
1: (Ab) (Cd)
a & b > c v d.
... ill-formed
a=b.
... ill-formed
(Ai & Bj > Cx).
... ill-formed
(x)(Sx > Px).
... ill-formed
(Ex)(Sx > Px).
... well-formed -
1: (Ex) (Sx>Px)
2: (Ex)(Sx>Px)
-(Ex)Ax.
... well-formed -
1: -(Ex) Ax
2: -(Ex)A x
3: -(Ex)Ax
(Ax)(Px > -x).
... well-formed -
1: (Ax) (Px>-x)
(Ax)(Px > -Ax).
... well-formed -
1: (Ax) (Px>-Ax)
2: (Ax)(Px>-Ax)
This grammar might also look familiar. It is the reason I had to change ALFA_LENGTH
from 16 to 25.
STATEMENTSEQUENCE =
STATEMENT [ '; STATEMENT ] ;
STATEMENT =
LETTER ': '= EXPRESSION
| 'B 'E 'G 'I 'N STATEMENTSEQUENCE 'E 'N 'D
| 'I 'F EXPRESSION 'T 'H 'E 'N STATEMENT
{ 'E 'L 'S 'E STATEMENT }
| 'W 'H 'I 'L 'E EXPRESSION 'D 'O STATEMENT
| 'R 'E 'A 'D LETTER
| 'W 'R 'I 'T 'E EXPRESSION ;
EXPRESSION =
FACTOR [ BINARYOPERATOR FACTOR ] ;
FACTOR =
LETTER
| DIGIT [ DIGIT ]
| '( EXPRESSION ') ;
LETTER =
'a | 'b | 'c | 'd | 'e | 'f | 'g | 'h | 'i |
'j | 'k | 'l | 'm | 'n | 'o | 'p | 'q | 'r |
's | 't | 'u | 'v | 'w | 'x | 'y | 'z ;
BINARYOPERATOR =
'+ | '- | '* | '/ | 'M 'O 'D | '< | '> | '= | '< '= | '> '= ;
DIGIT =
'0 | '1 | '2 | '3 | '4 | '5 | '6 | '7 | '8 | '9 .
i := 10;
WHILE i >= 1 DO
BEGIN WRITE i * i; i := i - 1 END.
... well-formed -
1: i:=1 0;WHILEi>=1DOBEGINWRITEi*i;i:=i-1END
2: i:=10 ;WHILEi>=1DOBEGINWRITEi*i;i:=i-1END
3: i:=10;WHILEi>=1DOBEGINWRITEi*i;i:=i-1END
BEGIN
i := 10;
WHILE i > 0 DO
BEGIN WRITE i * i; i := i - 1 END
END.
... well-formed -
1: BEGINi:=10;WHILEi>0DOBEGINWRITEi*i;i:=i-1ENDEND
IF a = b THEN IF c = d THEN e := f ELSE g := h.
... well-formed -
1: IFa=bTHENIFc=dTHENe:=f ELSEg:=h
2: IFa=bTHENIFc=dTHENe:=fELSEg:=h
3: IFa=bTHENIFc=dTHENe:=fELSEg:=h
For some reason, the following grammar and example makes the program quit without any warnings or errors. What is happening here? (The grammar is a slight extension of the one above.)
STATEMENTSEQUENCE =
STATEMENT [ '; STATEMENT ] ;
STATEMENT =
LETTER ': '= EXPRESSION
| 'B 'E 'G 'I 'N STATEMENTSEQUENCE 'E 'N 'D
| 'I 'F EXPRESSION 'T 'H 'E 'N STATEMENT
{ 'E 'L 'S 'E STATEMENT }
| 'W 'H 'I 'L 'E EXPRESSION 'D 'O STATEMENT
| 'R 'E 'A 'D LETTER
| 'W 'R 'I 'T 'E EXPRESSION
| 'C'O'N'S'T IDENT '= DIGIT [ ', IDENT '= DIGIT ]
| 'V'A'R IDENT [ ', IDENT ]
| 'P'R'O'C'E'D'U'R'E IDENT
| 'C'A'L'L IDENT ;
EXPRESSION =
FACTOR [ BINARYOPERATOR FACTOR ] ;
FACTOR =
LETTER
| DIGIT [ DIGIT ]
| '( EXPRESSION ') ;
LETTER =
'a | 'b | 'c | 'd | 'e | 'f | 'g | 'h | 'i |
'j | 'k | 'l | 'm | 'n | 'o | 'p | 'q | 'r |
's | 't | 'u | 'v | 'w | 'x | 'y | 'z ;
BINARYOPERATOR =
'+ | '- | '* | '/ | 'M 'O 'D | '< | '> | '= | '< '= | '> '= ;
DIGIT =
'0 | '1 | '2 | '3 | '4 | '5 | '6 | '7 | '8 | '9
| DIGIT [ DIGIT ] ;
IDENT = LETTER [ LETTER | DIGIT | IDENT ].
CONST m = 7, n = 85;
VAR x, y, z, q, r;
PROCEDURE multiply;
VAR a, b;
BEGIN a := x; b := y; z := 0;
while b > 0 do
BEGIN
IF b MOD 2 = 1 THEN z := z + a;
a := 2*a; b := b/2;
END
END.
... well-formed -
1: CONSTm=7 ,n=85;VARx,y,z,q,r;PROCEDUREmultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
2: CONSTm=7,n=8 5;VARx,y,z,q,r;PROCEDUREmultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
3: CONSTm=7,n=8 5;VARx,y,z,q,r;PROCEDUREmultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
4: CONSTm=7,n=85 ;VARx,y,z,q,r;PROCEDUREmultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
5: CONSTm=7,n=85;VARx ,y,z,q,r;PROCEDUREmultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
6: CONSTm=7,n=85;VARx,y ,z,q,r;PROCEDUREmultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
7: CONSTm=7,n=85;VARx,y,z ,q,r;PROCEDUREmultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
8: CONSTm=7,n=85;VARx,y,z,q ,r;PROCEDUREmultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
9: CONSTm=7,n=85;VARx,y,z,q,r ;PROCEDUREmultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
10: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREm ultiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
11: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREmu ltiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
12: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREmul tiply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
13: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREmult iply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
14: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREmulti ply;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
15: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREmultip ly;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
16: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREmultipl y;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
17: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREmultiply ;VARa,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
18: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREmultiply;VARa ,b;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND
19: CONSTm=7,n=85;VARx,y,z,q,r;PROCEDUREmultiply;VARa,b ;BEGI
Na:=x;b:=y;z:=0;whileb>0doBEGINIFbMOD2=1THENz:=z+a;a:=2*a;b:=b/2;ENDEND