X-Git-Url: https://deadsoftware.ru/gitweb?p=cpc.git;a=blobdiff_plain;f=src%2Fgeneric%2FDev%2FMod%2FCPR.cp;h=b3ef0524cb2474b2bafbbd6249c362ad5c3dac04;hp=aaf4c8afb54ce95487c4b72639b82485e631594f;hb=f2367fdce1d3ed0d4caeabca10d83c8d2c03b43e;hpb=d1c9d1e488c6e14e82570f2833779086aa0f44f9 diff --git a/src/generic/Dev/Mod/CPR.cp b/src/generic/Dev/Mod/CPR.cp index aaf4c8a..b3ef052 100644 --- a/src/generic/Dev/Mod/CPR.cp +++ b/src/generic/Dev/Mod/CPR.cp @@ -27,7 +27,7 @@ MODULE DevCPR; END; VAR - ch: CHAR; (* current character *) + ch-: CHAR; (* current character *) name: DevCPT.Name; (* ident *) VAR @@ -35,6 +35,7 @@ MODULE DevCPR; fold: INTEGER; (* condition folding *) scope: Selector; top: Context; + skip-: BOOLEAN; PROCEDURE err (n: SHORTINT); BEGIN DevCPM.err(n) @@ -84,14 +85,15 @@ MODULE DevCPR; 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; @@ -122,18 +124,19 @@ MODULE DevCPR; 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; @@ -143,47 +146,54 @@ MODULE DevCPR; 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; @@ -192,42 +202,39 @@ MODULE DevCPR; 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 @@ -251,7 +258,8 @@ MODULE DevCPR; 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*; @@ -260,8 +268,8 @@ MODULE DevCPR; Close; If(TRUE); NEW(scope); - New("TRUE", TRUE); - New("FALSE", FALSE) + Set("TRUE", TRUE); + Set("FALSE", FALSE) END Init; END DevCPR.