[TUHS] Software written in B

Angelo Papenhoff aap at papnet.eu
Sat Jun 24 00:01:21 AEST 2023


On 23/06/23, Sebastien F4GRX wrote:
> For my information, where are the initialization values for the 
> ctab[128] vector coming from?

Probably some mix between last1120c and what made sense to me.
Actually found a bug in my compiler related to this, will have to check
my earlier (tree) compiler for this too.

> Do you still have the version that generates a tree before codegen?

https://github.com/aap/b/blob/master/bc.b

> I know that generating code while parsing is possible for stack based 
> machines, this is also how Crenshaw describes it in its document (but 
> for 68k).

What I found somewhat difficult and why i opted for the tree-approach
was mainly handling lvalues (but also conditional operators get a bit
easier).
If you have 'x = y', the compiler is supposed to generate
	va; 1	/ lval of x
	a; 2	/ rval of y
	b1	/ =
but when you pop the = it's already too late to change the 'a' to a
'va'. So my solution was to remember one operator of output so i can
combine it with the next one. I'm still not entirely happy with it (the
build() function especially), but it doesn't seem entirely wrong and
does generate matching B code.
Still, if people have suggestions how to do this better, I'd love to get
some feedback on this.


aap


More information about the TUHS mailing list