index 03c3fe40dc5605797ee685f63cffa3b39de739e0..8802469cd23daaa568b389b42399ff165fa6cbca 100644 (file)
END;
VAR
END;
VAR
- ch: CHAR; (* current character *)
+ ch-: CHAR; (* current character *)
name: DevCPT.Name; (* ident *)
VAR
name: DevCPT.Name; (* ident *)
VAR
fold: INTEGER; (* condition folding *)
scope: Selector;
top: Context;
fold: INTEGER; (* condition folding *)
scope: Selector;
top: Context;
+ skip-: BOOLEAN;
+ used-: BOOLEAN;
PROCEDURE err (n: SHORTINT);
BEGIN DevCPM.err(n)
PROCEDURE err (n: SHORTINT);
BEGIN DevCPM.err(n)
END
END Get;
END
END Get;
- PROCEDURE New (IN name: DevCPT.Name; val: BOOLEAN): Selector;
+ PROCEDURE New (IN name: DevCPT.Name): Selector;
VAR s: Selector;
BEGIN
s := scope;
WHILE (s.next # NIL) & (s.next.name$ # name$) DO s := s.next END;
VAR s: Selector;
BEGIN
s := scope;
WHILE (s.next # NIL) & (s.next.name$ # name$) DO s := s.next END;
- IF s.next = NIL THEN NEW(s.next); s.next.name := name$; s.next.val := val
+ IF s.next = NIL THEN NEW(s.next); s.next.name := name$; s.next.val := FALSE
ELSE err(1)
END;
RETURN s.next
ELSE err(1)
END;
RETURN s.next
s.next.name := name$; s.next.val := val
END Set;
s.next.name := name$; s.next.val := val
END Set;
- PROCEDURE ^ Expression (VAR x: BOOLEAN);
+ PROCEDURE ^ Expression (VAR x: BOOLEAN; use: BOOLEAN);
- PROCEDURE Factor (VAR x: BOOLEAN);
+ PROCEDURE Factor (VAR x: BOOLEAN; use: BOOLEAN);
BEGIN
BEGIN
+ x := FALSE;
IF sym = ident THEN
IF sym = ident THEN
- x := Old(name).val; Get(sym);
+ IF use THEN x := Old(name).val END; Get(sym);
ELSIF sym = defined THEN
Get(sym);
IF sym = lpar THEN
Get(sym);
IF sym = ident THEN
ELSIF sym = defined THEN
Get(sym);
IF sym = lpar THEN
Get(sym);
IF sym = ident THEN
- x := Find(name) # NIL;
+ IF use THEN x := Find(name) # NIL END;
Get(sym)
ELSE err(48)
END;
Get(sym)
ELSE err(48)
END;
ELSE err(40)
END
ELSIF sym = lpar THEN
ELSE err(40)
END
ELSIF sym = lpar THEN
- Get(sym); Expression(x);
+ Get(sym); Expression(x, use);
IF sym # rpar THEN err(23)
ELSE Get(sym)
END
ELSIF sym = not THEN
IF sym # rpar THEN err(23)
ELSE Get(sym)
END
ELSIF sym = not THEN
- Get(sym); Factor(x); x := ~x
+ Get(sym); Factor(x, use); IF use THEN x := ~x END
ELSE
ELSE
- x := FALSE;
err(13)
END
END Factor;
err(13)
END
END Factor;
- PROCEDURE Term (VAR x: BOOLEAN);
+ PROCEDURE Term (VAR x: BOOLEAN; use: BOOLEAN);
VAR y: BOOLEAN;
BEGIN
VAR y: BOOLEAN;
BEGIN
- Factor(x);
+ Factor(x, use);
WHILE sym = and DO
WHILE sym = and DO
- Get(sym); Factor(y); x := x & y
+ Get(sym); Factor(y, use & x); IF use & x THEN x := x & y END
END
END Term;
END
END Term;
- PROCEDURE Expression (VAR x: BOOLEAN);
+ PROCEDURE Expression (VAR x: BOOLEAN; use: BOOLEAN);
VAR y: BOOLEAN;
BEGIN
VAR y: BOOLEAN;
BEGIN
- Term(x);
+ Term(x, use);
WHILE sym = or DO
WHILE sym = or DO
- Get(sym); Term(y); x := x OR y
+ Get(sym); Term(y, use & ~x); IF use & ~x THEN x := x OR y END
END
END Expression;
END
END Expression;
+ PROCEDURE Printable (): BOOLEAN;
+ VAR c: Context;
+ BEGIN
+ c := top;
+ WHILE (c # NIL) & c.val DO c := c.next END;
+ RETURN c = NIL
+ END Printable;
+
PROCEDURE If (cond: BOOLEAN);
VAR c: Context;
BEGIN
NEW(c); c.next := top; c.alt := FALSE; c.val := cond; c.ref := 0; top := c;
PROCEDURE If (cond: BOOLEAN);
VAR c: Context;
BEGIN
NEW(c); c.next := top; c.alt := FALSE; c.val := cond; c.ref := 0; top := c;
- INC(fold)
+ INC(fold); skip := ~Printable(); used := TRUE
END If;
PROCEDURE Else;
BEGIN
IF top.alt THEN err(14) (* double ELSE *)
END If;
PROCEDURE Else;
BEGIN
IF top.alt THEN err(14) (* double ELSE *)
- ELSE top.alt := TRUE; top.val := ~top.val;
+ ELSE top.alt := TRUE; top.val := ~top.val; skip := ~Printable()
END
END Else;
END
END Else;
BEGIN
i := 0; ref := top.ref; DEC(fold, ref + 1);
WHILE (top # NIL) & (i <= ref) DO top := top.next; INC(i) END;
BEGIN
i := 0; ref := top.ref; DEC(fold, ref + 1);
WHILE (top # NIL) & (i <= ref) DO top := top.next; INC(i) END;
- IF top = NIL THEN err(51); fold := 0; If(TRUE) END
+ IF top = NIL THEN err(51); fold := 0; If(TRUE) END;
+ skip := ~Printable()
END End;
END End;
- PROCEDURE Printable* (): BOOLEAN;
- VAR c: Context;
- BEGIN
- c := top;
- WHILE (c # NIL) & c.val DO c := c.next END;
- RETURN c = NIL
- END Printable;
-
PROCEDURE Parse*;
PROCEDURE Parse*;
- VAR val: BOOLEAN; s: Selector;
+ VAR val: BOOLEAN; s: Selector; use: BOOLEAN;
BEGIN
BEGIN
- Get(sym);
+ ch := " "; Get(sym); use := ~skip;
IF sym = new THEN
Get(sym);
IF sym = new THEN
Get(sym);
- IF sym = ident THEN s := New(name, FALSE); Get(sym)
+ IF sym = ident THEN
+ IF use THEN s := New(name) END; Get(sym);
+ IF (sym = plus) OR (sym = minus) THEN
+ IF use THEN s.val := sym = plus END; Get(sym)
+ END
ELSE err(48)
ELSE err(48)
- END;
- IF (sym = plus) OR (sym = minus) THEN
- s.val := sym = plus; Get(sym)
END
END
- ELSIF sym = error THEN
- IF Printable() THEN err(501) END; Get(sym)
ELSIF sym = ident THEN
ELSIF sym = ident THEN
- Get(sym);
- IF sym = plus THEN Old(name).val := TRUE; Get(sym)
- ELSIF sym = minus THEN Old(name).val := FALSE; Get(sym)
+ IF use THEN s := Old(name) END; Get(sym);
+ IF (sym = plus) OR (sym = minus) THEN
+ IF use THEN s.val := sym = plus END; Get(sym)
ELSE err(41)
END
ELSE err(41)
END
+ ELSIF sym = error THEN
+ IF use THEN err(501) END; Get(sym)
ELSIF sym = if THEN
ELSIF sym = if THEN
- Get(sym); Expression(val); If(val);
+ Get(sym); Expression(val, use); If(val);
IF sym = then THEN Get(sym)
ELSE err(27)
END
ELSIF sym = elsif THEN
IF fold <= 1 THEN err(14) END; (* ELSIF without IF *)
IF sym = then THEN Get(sym)
ELSE err(27)
END
ELSIF sym = elsif THEN
IF fold <= 1 THEN err(14) END; (* ELSIF without IF *)
- Else; Get(sym); Expression(val); If(val); INC(top.ref);
+ Else; Get(sym); Expression(val, use); If(val); INC(top.ref);
IF sym = then THEN Get(sym)
ELSE err(27)
END
IF sym = then THEN Get(sym)
ELSE err(27)
END
PROCEDURE Close*;
BEGIN
ch := " "; sym := eof; name := "";
PROCEDURE Close*;
BEGIN
ch := " "; sym := eof; name := "";
- fold := 0; top := NIL; scope := NIL
+ fold := 0; top := NIL; scope := NIL;
+ skip := FALSE; used := FALSE
END Close;
PROCEDURE Init*;
END Close;
PROCEDURE Init*;
If(TRUE);
NEW(scope);
Set("TRUE", TRUE);
If(TRUE);
NEW(scope);
Set("TRUE", TRUE);
- Set("FALSE", FALSE)
+ Set("FALSE", FALSE);
+ used := FALSE
END Init;
END DevCPR.
END Init;
END DevCPR.