r/Compilers • u/Gordon-NZ • Oct 17 '26
Brinch Hansen Compier 'emit' routine problem
Just for fun I am implementing the sample compiler in the appendices of 'Brinch Hansen on Pascal Compilers' - as a first step.
One puzzle: he uses a procedure named emit to write to files: (pg 242)
procedure emit(value: Integer);
begin if emitting then write(chr(value)
end;
But this procedure is used to write integers up to his maxint of 32767. No Pascal I know has chr() available for arguments > 255.
Is this something special in his OS or bootstrapping compiler, Pascal* ?
TIA
Gordon
1
Upvotes
3
u/cxzuk Oct 17 '26
Hi Gordon,
I think that's probably the right conclusion, although I haven't been able to find much documentation on Pascal*.
I've skimmed Brinch Hansen's book (SSL is broken)
Emit2() can absolutely pass the full range of an integer to Emit().
The book was written in 1985, 7-bit and 8-bit characters were common. It's possible that Pascal* used a word-sized Char, the same size as Integer, but without a definition of chr() and Write(), I can only speculate.
I think we can safely say that truncating an integer to an 8-bit character would result in incorrect behaviour, and that this code relies on implementation-specific semantics rather than being portable Pascal.
Good luck!
M ✌
1
u/AustinVelonaut Oct 17 '26
Yeah, that looks wrong, for standard Pascal. It is almost like
stris intended, here, instead ofchr(at least forEmit2, which takes an integer argument as its second value).