Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax of auto declarations #1

Closed
slorquet opened this issue Jun 23, 2023 · 5 comments
Closed

Syntax of auto declarations #1

slorquet opened this issue Jun 23, 2023 · 5 comments

Comments

@slorquet
Copy link

slorquet commented Jun 23, 2023

Hello,

After having some discussion about the B language with unix experts on the TUHS mailing list it appears that the constant values in auto declarations are not initial values but vector dimensions.

The reference for this is Ken Thompson's language specification here:

https://www.bell-labs.com/usr/dmr/www/kbman.html

Later on, the B language was ported to the H6070 computer, and the spec was evolved to include brackets as described in this document, while changing the meaning of the constant to an unusual one :

https://www.bell-labs.com/usr/dmr/www/bref.pdf

So in your fibonacci example, the initial values of variables should be defined by assignment expressions at the beginning of the code. The syntax you have used here:

auto a, b 1, c, i 0;

is in fact incorrect and means in normal C:

int a, b[1], c, i[0];

which makes no sense, but the actual required syntax is:

auto a, b, c, i;
b=1;
i=0;

Best regards

@Spydr06
Copy link
Owner

Spydr06 commented Jun 23, 2023

Thank you! This wasn't quite clear to me from the kbman alone, I'll definitely fix it in the compiler

Just out of curiosity, has this compiler been useful for you? You seem to be somewhat connected in that area.

@Spydr06
Copy link
Owner

Spydr06 commented Jun 23, 2023

Commit da85e36 implements the auto a [N]; syntax and fixes auto a N; to behave correctly.
There are still some issues with the stack offset though, will fix that soon!

@slorquet
Copy link
Author

Hi,
I did a review of other compiler projects to find code examples to test my compiler on.
So I had a look at your compiler, which confimed that a recursive descent parser was the right way to go, but I avoided looking at it in too many details, not to be influenced by it :)

My own compiler (not on github) has a goal of generating code for retro 8-bit targets. Apart that it has nothing special. Recursive descent written in C.

@Spydr06
Copy link
Owner

Spydr06 commented Jun 24, 2023

Oh nice, sounds like a fun project!

@Spydr06
Copy link
Owner

Spydr06 commented Sep 1, 2023

Stack alignment issues (hopefully) fixed with adf8d94

@Spydr06 Spydr06 closed this as completed Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants