Dimensionality of program code

Stewart Gordon smjg_1998 at yahoo.com
Fri Jan 18 11:46:57 PST 2013


On 17/01/2013 22:01, Era Scarecrow wrote:
<snip>
>   As I recall for the compilers very early on, all comments and unneeded
> whitespace were simply removed before compiling, leaving you with one
> very long command string. The /**/ comment syntax makes perfect sense in
> this case; Later tools more memory and hardware power make it more
> manageable; but // requires 2d code to properly compile until the
> comments are stripped.

Doesn't quite follow, because as far as the computer is concerned a line 
break is just another character.

Though in order to know whether a newline is whitespace, the lexer needs 
to know whether it's lexing a // comment or not.  But this 
context-sensitive character classification is something we already 
needed in order to read strings correctly.  Unless these early languages 
didn't allow you to have consecutive spaces in a string literal or 
required a special notation for them.

> // c example, originally isprime and main don't have
> // return types, defaulting to int instead.

Does the return type of a function still default to int if unspecified 
in current C, either according to the ANSI standard or according to most 
compilers?

> int isprime(int n){int cnt=2;if(n<2)return
> 0;for(;cnt<n;cnt++)if((n%cnt)==0)return 0;return 1;}int main(){int
> cnt=2;for(;cnt<1000000;cnt++)if (isprime(cnt))printf("%d \n", cnt);}
>
>   It's one of the reasons the syntax requires a semicolon after each
> statement so it can tell obviously where something ends.

But Dennis could have easily designed it to use a newline instead of a 
semicolon.  Indeed, there are a number of programming languages that 
basically do this.

But other languages do more than this, like Python and Haskell which are 
indent-sensitive, and early FORTRAN with its strict rules on code 
layout.  Indeed, considering these, you could well ask where to draw the 
line between a 1D language and a 2D language.

Stewart.


More information about the Digitalmars-d mailing list