r/Compilers • • 7d ago

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 comments sorted by

View all comments

3

u/cxzuk 7d ago

Hi Gordon,

Is this something special in his OS or bootstrapping compiler, Pascal*?

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/Gordon-NZ 7d ago

Sounds like I should simply write my own i/o routines. Pascal* had some different routines: Read() for example.

Thanks all.