/* Copyright (c) 1979 Regents of the University of California */
* pi - Pascal interpreter code translator
* Charles Haley, Bill Joy UCB
* Version 1.2 January 1979
error("Type declarations must precede var declarations");
error("All types must be declared in one type part");
* Forechain is the head of a list of types that
* might be self referential. We chain them up and
if (np
!= NIL
&& (tdecl
[0] == T_ID
|| tdecl
[0] == T_TYID
))
enter(defnl(tid
, TYPE
, np
, 0))->nl_flags
=| NMOD
;
enter(defnl(tid
, TYPE
, np
, 0));
send(REVTYPE
, tline
, tid
, tdecl
);
* Return a type pointer (into the namelist)
* from a parse tree for a type, building
* namelist entries as needed.
error("%s is a %s, not a type as required", r
[1], classes
[np
->class]);
np
= defnl(0, PTR
, 0, r
[2]);
if (np
->nl_flags
& NFILES
)
error("Files cannot be members of files");
np
= defnl(0, FILE, np
, 0);
if (np
->type
== nl
+TDOUBLE
) {
error("Set of real is not allowed");
if (np
->class != RANGE
&& np
->class != SCAL
) {
error("Set type must be range or scalar, not %s", nameof(np
));
error("Implementation restriction: sets must be indexed by 16 bit quantities");
np
= defnl(0, SET
, np
, 0);
* Scalar (enumerated) types
register struct nl
*np
, *op
;
np
= defnl(0, SCAL
, 0, 0);
for (; v
!= NIL
; v
= v
[2]) {
op
= enter(defnl(v
[1], CONST
, np
, ++i
));
register struct nl
*lp
, *hp
;
if (lp
== NIL
|| hp
== NIL
)
if (norange(lp
) || norange(hp
))
error("Can't mix %ss and %ss in subranges", nameof(lp
), nameof(hp
));
if (c
== TSCAL
&& scalar(lp
) != scalar(hp
)) {
error("Scalar types must be identical in subranges");
error("Range lower bound exceeds upper bound");
lp
= defnl(0, RANGE
, hp
->type
, 0);
lp
->range
[0] = con
.crval
;
error("Subrange of real is not allowed");
error("Subrange bounds must be Boolean, character, integer or scalar, not %s", nameof(p
));
* Declare arrays and chain together the dimension specification
register struct nl
*tp
, *ltp
;
np
= defnl(0, ARRAY
, tp
, 0);
np
->nl_flags
=| (tp
->nl_flags
) & NFILES
;
for (tl
= r
[2]; tl
!= NIL
; tl
= tl
[2]) {
if (tp
->class == RANGE
&& tp
->type
== nl
+TDOUBLE
) {
error("Index type for arrays cannot be real");
if (tp
->class != RANGE
&& tp
->class != SCAL
) {
error("Array index type is a %s, not a range or scalar as required", classes
[tp
->class]);
if (tp
->class == RANGE
&& bytes(tp
->range
[0], tp
->range
[1]) > 2) {
error("Value of dimension specifier too large or small for this implementation");
* Delayed processing for pointers to
* allow self-referential and mutually
* recursive pointer constructs.
register struct nl
*p
, *q
;
for (p
= forechain
; p
!= NIL
; p
= p
->nl_next
) {
if (p
->class == PTR
&& p
->value
[0] != 0)
p
->type
= gtype(p
->value
[0]);
if (p
->type
!= NIL
&& (p
->type
->nl_flags
& NFILES
))
error("Files cannot be members of dynamic structures");