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
One-pass Compiler
41–44 of 44 posts
Re: One-pass Compiler
#42I 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.
Re: One-pass Compiler
#43I 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.
Too late to edit now!
Re: One-pass Compiler
#44Earlier 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