From e52a3df8538aa38dde9851e00b98b0cffe3c6750 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sat, 14 Dec 2019 18:11:25 +0300 Subject: [PATCH] add function DEFINED to preprocessor --- src/generic/Dev/Mod/CPR.cp | 47 +++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/generic/Dev/Mod/CPR.cp b/src/generic/Dev/Mod/CPR.cp index 233b121..b43b539 100644 --- a/src/generic/Dev/Mod/CPR.cp +++ b/src/generic/Dev/Mod/CPR.cp @@ -12,6 +12,9 @@ MODULE DevCPR; not = 10; and = 11; or = 12; rpar = 13; lpar = 14; endcom = 15; eof = 16; + (* func numbers *) + var = 0; defined = 1; + TYPE Context = POINTER TO RECORD next: Context; (* upper level block *) @@ -23,7 +26,8 @@ MODULE DevCPR; Selector = POINTER TO RECORD next: Selector; name: DevCPT.Name; - val: BOOLEAN + val: BOOLEAN; + num: BYTE END; VAR @@ -82,14 +86,16 @@ MODULE DevCPR; END END Get; - PROCEDURE New (IN name: DevCPT.Name; val: BOOLEAN); + PROCEDURE New (IN name: DevCPT.Name; val: BOOLEAN): 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.num := var; s.next.val := val ELSE err(1) - END + END; + RETURN s.next END New; PROCEDURE Old (IN name: DevCPT.Name): Selector; @@ -98,7 +104,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.val := FALSE + err(0); NEW(s.next); s.next.name := name$; s.next.num := var; s.next.val := FALSE END; RETURN s.next END Old; @@ -116,15 +122,32 @@ MODULE DevCPR; 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 END + IF s.next = NIL THEN NEW(s.next) END; + s.next.name := name$; s.next.num := var; s.next.val := val END Set; PROCEDURE ^ Expression (VAR x: BOOLEAN); PROCEDURE Factor (VAR x: BOOLEAN); + VAR s: Selector; BEGIN x := FALSE; IF sym = ident THEN - x := Old(name).val; Get(sym) + s := Old(name); Get(sym); + IF s.num = var THEN + x := s.val + ELSIF sym = lpar THEN + Get(sym); + ASSERT(s.num = defined); + IF sym = ident THEN + x := Find(name) # NIL; Get(sym) + ELSE err(48) + END; + IF sym # rpar THEN err(23) + ELSE Get(sym) + END + ELSE + err(40) + END ELSIF sym = lpar THEN Get(sym); Expression(x); IF sym # rpar THEN err(23) @@ -178,12 +201,12 @@ MODULE DevCPR; END End; PROCEDURE Parse*; - VAR val: BOOLEAN; + VAR val: BOOLEAN; s: Selector; BEGIN Get(sym); IF sym = new THEN Get(sym); - IF sym = ident THEN New(name, FALSE); Get(sym) + IF sym = ident THEN s := New(name, FALSE); Get(sym) ELSE err(48) END ELSIF sym = ident THEN @@ -235,12 +258,14 @@ MODULE DevCPR; END Close; PROCEDURE Init*; + VAR s: Selector; BEGIN Close; If(TRUE); NEW(scope); - New("TRUE", TRUE); - New("FALSE", FALSE) + s := New("TRUE", TRUE); + s := New("FALSE", FALSE); + s := New("DEFINED", FALSE); s.num := defined END Init; END DevCPR. -- 2.29.2