Live data from Hacker News

One-pass Compiler

keleshev.com

41–44 of 44 posts

Re: One-pass Compiler

#41

Earlier quoted context omitted.

Older versions of C had the restriction that variables could only be declared at the start of a block. Supposedly this was due to the original C compiler being one-pass. It's easier to keep track of the size of the stack frame if you see all declarations in one place. Though I think with a frame pointer you could make it work anyway. You have essentially the same complications if you allow programmers to open a block…

>Older versions of C had the restriction that variables could only be declared at the start of a block. Pascal also has that restriction Although Delphi does not have it anymore. But FreePascal still has it, even in Delphi compatible mode. The FreePascal developers have also said, they will keep that restriction to improve readability. The code could not be read anymore if variables were placed willy-nilly everywhere

I wonder if Delphi still a one pass compiler?

Re: One-pass Compiler

#42

I wrote something very similar recently, also a single-pass, but with a trivial internal representation: https://github.com/skx/math-compiler The real difference between the compiler in the example, and mine, is that I handle floating-point operations and also explicitly use printf to show the output. (Because otherwise your return value is limited to an 8bit number.)

Because otherwise your return value is limited to an 8bit number Only on Linux; Windows lets you use the full 32 bits.

That's true. Though I guess even there there are limitations, because you can't return non-integers :)

Re: One-pass Compiler

#43

I wrote something very similar recently, also a single-pass, but with a trivial internal representation: https://github.com/skx/math-compiler The real difference between the compiler in the example, and mine, is that I handle floating-point operations and also explicitly use printf to show the output. (Because otherwise your return value is limited to an 8bit number.)

This is nice. The -debug flag is a cool feature. But if you first build a representation of the whole program in memory, then traverse that representation to generate code, it's not really single-pass.

Sorry my comment was wrong, I should have said "not a single-pass", that's why I mentiond the trivial internal representation.

Too late to edit now!

Re: One-pass Compiler

#44

Earlier quoted context omitted.

Older versions of C had the restriction that variables could only be declared at the start of a block. Supposedly this was due to the original C compiler being one-pass. It's easier to keep track of the size of the stack frame if you see all declarations in one place. Though I think with a frame pointer you could make it work anyway. You have essentially the same complications if you allow programmers to open a block…

>Older versions of C had the restriction that variables could only be declared at the start of a block. Pascal also has that restriction Although Delphi does not have it anymore. But FreePascal still has it, even in Delphi compatible mode. The FreePascal developers have also said, they will keep that restriction to improve readability. The code could not be read anymore if variables were placed willy-nilly everywhere

I’ve heard the readability justification for C restriction, but it doesn’t make sense: this prevent ´constification’ of variables (make the variable contains only one value)..
Post reply on HN