From: DeaDDooMER Date: Sat, 14 Dec 2019 18:58:46 +0000 (+0300) Subject: reimplenet DEFINED as operator X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=d1c9d1e488c6e14e82570f2833779086aa0f44f9;p=cpc.git reimplenet DEFINED as operator --- diff --git a/src/generic/Dev/Mod/CPR.cp b/src/generic/Dev/Mod/CPR.cp index 851d82e..aaf4c8a 100644 --- a/src/generic/Dev/Mod/CPR.cp +++ b/src/generic/Dev/Mod/CPR.cp @@ -9,11 +9,8 @@ MODULE DevCPR; null = 0; if = 1; then = 2; else = 3; elsif = 4; end = 5; new = 6; error = 7; ident = 8; plus = 9; minus = 10; - not = 11; and = 12; or = 13; rpar = 14; lpar = 15; - endcom = 16; eof = 17; - - (* func numbers *) - var = 0; defined = 1; + not = 11; and = 12; or = 13; rpar = 14; lpar = 15; defined = 16; + endcom = 17; eof = 18; TYPE Context = POINTER TO RECORD @@ -26,8 +23,7 @@ MODULE DevCPR; Selector = POINTER TO RECORD next: Selector; name: DevCPT.Name; - val: BOOLEAN; - num: BYTE + val: BOOLEAN END; VAR @@ -70,6 +66,7 @@ MODULE DevCPR; IF ch = ">" THEN sym := endcom; DevCPM.Get(ch) END | "+": sym := plus; DevCPM.Get(ch) | "-": sym := minus; DevCPM.Get(ch) + | "D": Identifier(sym); IF name = "DEFINED" THEN sym := defined END | "E": Identifier(sym); IF name = "END" THEN sym := end ELSIF name = "ELSE" THEN sym := else @@ -80,23 +77,21 @@ MODULE DevCPR; | "N": Identifier(sym); IF name = "NEW" THEN sym := new END | "O": Identifier(sym); IF name = "OR" THEN sym := or END | "T": Identifier(sym); IF name = "THEN" THEN sym := then END - | "A".."D", "J".."M", "P".."S", "U".."Z", "a".."z", "_": Identifier(sym) + | "A".."C", "J".."M", "P".."S", "U".."Z", "a".."z", "_": Identifier(sym) | "~": sym := not; DevCPM.Get(ch) ELSE IF Strings.IsIdent(ch) THEN Identifier(sym) ELSE sym := null; DevCPM.Get(ch) END END END Get; - PROCEDURE New (IN name: DevCPT.Name; val: BOOLEAN): Selector; + PROCEDURE New (IN name: DevCPT.Name; val: BOOLEAN); 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.num := var; s.next.val := val + IF s.next = NIL THEN NEW(s.next); s.next.name := name$; s.next.val := val ELSE err(1) - END; - RETURN s.next + END END New; PROCEDURE Old (IN name: DevCPT.Name): Selector; @@ -105,7 +100,7 @@ MODULE DevCPR; s := scope; WHILE (s.next # NIL) & (s.next.name$ # name$) DO s := s.next END; IF s.next = NIL THEN - err(0); NEW(s.next); s.next.name := name$; s.next.num := var; s.next.val := FALSE + err(0); NEW(s.next); s.next.name := name$; s.next.val := FALSE END; RETURN s.next END Old; @@ -124,31 +119,29 @@ MODULE DevCPR; s := scope; WHILE (s.next # NIL) & (s.next.name$ # name$) DO s := s.next END; IF s.next = NIL THEN NEW(s.next) END; - s.next.name := name$; s.next.num := var; s.next.val := val + s.next.name := name$; s.next.val := val END Set; PROCEDURE ^ Expression (VAR x: BOOLEAN); PROCEDURE Factor (VAR x: BOOLEAN); - VAR s: Selector; - BEGIN x := FALSE; + BEGIN IF sym = ident THEN - s := Old(name); Get(sym); - IF s.num = var THEN - x := s.val - ELSIF sym = lpar THEN + x := Old(name).val; Get(sym); + ELSIF sym = defined THEN + Get(sym); + IF sym = lpar THEN Get(sym); - ASSERT(s.num = defined); IF sym = ident THEN - x := Find(name) # NIL; Get(sym) + x := Find(name) # NIL; + Get(sym) ELSE err(48) END; IF sym # rpar THEN err(23) ELSE Get(sym) END - ELSE - err(40) - END + ELSE err(40) + END ELSIF sym = lpar THEN Get(sym); Expression(x); IF sym # rpar THEN err(23) @@ -157,6 +150,7 @@ MODULE DevCPR; ELSIF sym = not THEN Get(sym); Factor(x); x := ~x ELSE + x := FALSE; err(13) END END Factor; @@ -210,12 +204,12 @@ MODULE DevCPR; END Printable; PROCEDURE Parse*; - VAR val: BOOLEAN; s: Selector; + VAR val: BOOLEAN; BEGIN Get(sym); IF sym = new THEN Get(sym); - IF sym = ident THEN s := New(name, FALSE); Get(sym) + IF sym = ident THEN New(name, FALSE); Get(sym) ELSE err(48) END ELSIF sym = error THEN @@ -266,9 +260,8 @@ MODULE DevCPR; Close; If(TRUE); NEW(scope); - s := New("TRUE", TRUE); - s := New("FALSE", FALSE); - s := New("DEFINED", FALSE); s.num := defined + New("TRUE", TRUE); + New("FALSE", FALSE) END Init; END DevCPR.