index aaf4c8afb54ce95487c4b72639b82485e631594f..b3ef0524cb2474b2bafbbd6249c362ad5c3dac04 100644 (file)
END;
VAR
- ch: CHAR; (* current character *)
+ ch-: CHAR; (* current character *)
name: DevCPT.Name; (* ident *)
VAR
fold: INTEGER; (* condition folding *)
scope: Selector;
top: Context;
+ skip-: BOOLEAN;
PROCEDURE err (n: SHORTINT);
BEGIN DevCPM.err(n)
END
END Get;
- PROCEDURE New (IN name: DevCPT.Name; val: BOOLEAN);
+ 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;
- 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
+ END;
+ RETURN s.next
END New;
PROCEDURE Old (IN name: DevCPT.Name): Selector;
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
+ x := FALSE;
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
- x := Find(name) # NIL;
+ IF use THEN x := Find(name) # NIL END;
Get(sym)
ELSE err(48)
END;
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
- Get(sym); Factor(x); x := ~x
+ Get(sym); Factor(x, use); IF use THEN x := ~x END
ELSE
- x := FALSE;
err(13)
END
END Factor;
- PROCEDURE Term (VAR x: BOOLEAN);
+ PROCEDURE Term (VAR x: BOOLEAN; use: BOOLEAN);
VAR y: BOOLEAN;
BEGIN
- Factor(x);
+ Factor(x, use);
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;
- PROCEDURE Expression (VAR x: BOOLEAN);
+ PROCEDURE Expression (VAR x: BOOLEAN; use: BOOLEAN);
VAR y: BOOLEAN;
BEGIN
- Term(x);
+ Term(x, use);
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;
+ 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;
- INC(fold)
+ INC(fold); skip := ~Printable()
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;
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;
- 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*;
- VAR val: BOOLEAN;
+ VAR val: BOOLEAN; s: Selector; use: BOOLEAN;
BEGIN
- Get(sym);
+ ch := " "; Get(sym); use := ~skip;
IF sym = new THEN
Get(sym);
- IF sym = ident THEN 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)
END
- ELSIF sym = error THEN
- IF Printable() THEN err(501) END; Get(sym)
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
+ ELSIF sym = error THEN
+ IF use THEN err(501) END; Get(sym)
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 *)
- 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
PROCEDURE Close*;
BEGIN
ch := " "; sym := eof; name := "";
- fold := 0; top := NIL; scope := NIL
+ fold := 0; top := NIL; scope := NIL;
+ skip := FALSE
END Close;
PROCEDURE Init*;
Close;
If(TRUE);
NEW(scope);
- New("TRUE", TRUE);
- New("FALSE", FALSE)
+ Set("TRUE", TRUE);
+ Set("FALSE", FALSE)
END Init;
END DevCPR.