3 IMPORT Strings
, DevCPM
, DevCPT
;
6 MaxIdLen
= LEN(DevCPT
.Name
);
10 if
= 1; then
= 2; else
= 3; elsif
= 4; end
= 5;
11 new
= 6; error
= 7; ident
= 8; plus
= 9; minus
= 10;
12 not
= 11; and
= 12; or
= 13; rpar
= 14; lpar
= 15; defined
= 16;
13 endcom
= 17; eof
= 18;
16 Context
= POINTER TO RECORD
17 next
: Context
; (* upper level block *)
18 alt
: BOOLEAN; (* else branch *)
19 val
: BOOLEAN; (* condition value, inverted if alt *)
20 ref
: INTEGER (* ELSIF count *)
23 Selector
= POINTER TO RECORD
30 ch
: CHAR; (* current character *)
31 name
: DevCPT
.Name
; (* ident *)
34 sym
: BYTE; (* parser symbol *)
35 fold
: INTEGER; (* condition folding *)
39 PROCEDURE err (n
: SHORTINT);
43 PROCEDURE Identifier (VAR sym
: BYTE);
44 VAR i
, res
: INTEGER; n
: ARRAY MaxIdLen
OF CHAR;
47 n
[i
] := ch
; INC(i
); DevCPM
.Get(ch
)
48 UNTIL ~Strings
.IsIdent(ch
) OR (i
= MaxIdLen
);
49 IF i
= MaxIdLen
THEN err(240); DEC(i
) END ;
50 n
[i
] := 0X
; Strings
.StringToUtf8(n
, name
, res
); sym
:= ident
;
51 IF res
= 1 (*truncated*) THEN err(240) END
54 PROCEDURE Get (VAR sym
: BYTE);
56 DevCPM
.errpos
:= DevCPM
.curpos
- 1;
57 WHILE (ch
# DevCPM
.Eot
) & ((ch
<= " ") OR (ch
= 0A0X
)) DO DevCPM
.Get(ch
) END;
58 DevCPM
.startpos
:= DevCPM
.curpos
- 1;
60 | DevCPM
.Eot
: sym
:= eof
61 |
"&": sym
:= and
; DevCPM
.Get(ch
)
62 |
"(": sym
:= lpar
; DevCPM
.Get(ch
)
63 |
")": sym
:= rpar
; DevCPM
.Get(ch
)
65 sym
:= null
; DevCPM
.Get(ch
);
66 IF ch
= ">" THEN sym
:= endcom
; DevCPM
.Get(ch
) END
67 |
"+": sym
:= plus
; DevCPM
.Get(ch
)
68 |
"-": sym
:= minus
; DevCPM
.Get(ch
)
69 |
"D": Identifier(sym
); IF name
= "DEFINED" THEN sym
:= defined
END
70 |
"E": Identifier(sym
);
71 IF name
= "END" THEN sym
:= end
72 ELSIF name
= "ELSE" THEN sym
:= else
73 ELSIF name
= "ELSIF" THEN sym
:= elsif
74 ELSIF name
= "ERROR" THEN sym
:= error
76 |
"I": Identifier(sym
); IF name
= "IF" THEN sym
:= if
END
77 |
"N": Identifier(sym
); IF name
= "NEW" THEN sym
:= new
END
78 |
"O": Identifier(sym
); IF name
= "OR" THEN sym
:= or
END
79 |
"T": Identifier(sym
); IF name
= "THEN" THEN sym
:= then
END
80 |
"A".."C", "J".."M", "P".."S", "U".."Z", "a".."z", "_": Identifier(sym
)
81 |
"~": sym
:= not
; DevCPM
.Get(ch
)
83 IF Strings
.IsIdent(ch
) THEN Identifier(sym
) ELSE sym
:= null
; DevCPM
.Get(ch
) END
87 PROCEDURE New (IN name
: DevCPT
.Name
; val
: BOOLEAN);
91 WHILE (s
.next
# NIL) & (s
.next
.name$
# name$
) DO s
:= s
.next
END;
92 IF s
.next
= NIL THEN NEW(s
.next
); s
.next
.name
:= name$
; s
.next
.val
:= val
97 PROCEDURE Old (IN name
: DevCPT
.Name
): Selector
;
101 WHILE (s
.next
# NIL) & (s
.next
.name$
# name$
) DO s
:= s
.next
END;
103 err(0); NEW(s
.next
); s
.next
.name
:= name$
; s
.next
.val
:= FALSE
108 PROCEDURE Find (IN name
: DevCPT
.Name
): Selector
;
112 WHILE (s
.next
# NIL) & (s
.next
.name$
# name$
) DO s
:= s
.next
END;
116 PROCEDURE Set
* (IN name
: DevCPT
.Name
; val
: BOOLEAN);
120 WHILE (s
.next
# NIL) & (s
.next
.name$
# name$
) DO s
:= s
.next
END;
121 IF s
.next
= NIL THEN NEW(s
.next
) END;
122 s
.next
.name
:= name$
; s
.next
.val
:= val
125 PROCEDURE ^
Expression (VAR x
: BOOLEAN);
127 PROCEDURE Factor (VAR x
: BOOLEAN);
130 x
:= Old(name
).val
; Get(sym
);
131 ELSIF sym
= defined
THEN
136 x
:= Find(name
) # NIL;
140 IF sym
# rpar
THEN err(23)
145 ELSIF sym
= lpar
THEN
146 Get(sym
); Expression(x
);
147 IF sym
# rpar
THEN err(23)
151 Get(sym
); Factor(x
); x
:= ~x
158 PROCEDURE Term (VAR x
: BOOLEAN);
163 Get(sym
); Factor(y
); x
:= x
& y
167 PROCEDURE Expression (VAR x
: BOOLEAN);
172 Get(sym
); Term(y
); x
:= x
OR y
176 PROCEDURE If (cond
: BOOLEAN);
179 NEW(c
); c
.next
:= top
; c
.alt
:= FALSE
; c
.val
:= cond
; c
.ref
:= 0; top
:= c
;
185 IF top
.alt
THEN err(14) (* double ELSE *)
186 ELSE top
.alt
:= TRUE
; top
.val
:= ~top
.val
;
193 i
:= 0; ref
:= top
.ref
; DEC(fold
, ref
+ 1);
194 WHILE (top
# NIL) & (i
<= ref
) DO top
:= top
.next
; INC(i
) END;
195 IF top
= NIL THEN err(51); fold
:= 0; If(TRUE
) END
198 PROCEDURE Printable
* (): BOOLEAN;
202 WHILE (c
# NIL) & c
.val
DO c
:= c
.next
END;
212 IF sym
= ident
THEN New(name
, FALSE
); Get(sym
)
215 ELSIF sym
= error
THEN
216 IF Printable() THEN err(501) END; Get(sym
)
217 ELSIF sym
= ident
THEN
219 IF sym
= plus
THEN Old(name
).val
:= TRUE
; Get(sym
)
220 ELSIF sym
= minus
THEN Old(name
).val
:= FALSE
; Get(sym
)
224 Get(sym
); Expression(val
); If(val
);
225 IF sym
= then
THEN Get(sym
)
228 ELSIF sym
= elsif
THEN
229 IF fold
<= 1 THEN err(14) END; (* ELSIF without IF *)
230 Else
; Get(sym
); Expression(val
); If(val
); INC(top
.ref
);
231 IF sym
= then
THEN Get(sym
)
234 ELSIF sym
= else
THEN
235 IF fold
<= 1 THEN err(14) END; (* ELSE without IF *)
238 IF fold
<= 1 THEN err(14) END; (* END without IF *)
243 IF sym
# endcom
THEN err(5) ELSE DevCPM
.errpos
:= DevCPM
.curpos
- 1 END
248 IF fold
# 1 THEN err(14) END
253 ch
:= " "; sym
:= eof
; name
:= "";
254 fold
:= 0; top
:= NIL; scope
:= NIL