Yeah, I wondered about that. Having heard that C was designed in part for
the parser. A parser with no lookahead (or maybe 1 char of lookahead) was
used, which is why hex numbers start with "0x" instead of being suffixed
with "_16", just to contrive an example.

I would be curious to hear the author say whether this played a part in his
decision.

Bruce


-----Original Message-----
From: Ernest E Vogelsinger [mailto:ernest@;vogelsinger.at]
Sent: Tuesday, November 12, 2002 3:54 PM
To: Jonathan Rosenberg (Tabby's Place)
Cc: Marco Tabini; Jonathan Rosenberg (Tabby's Place); PHP-General
Subject: RE: [PHP] Why $ on variable names?


At 22:40 12.11.2002, Jonathan Rosenberg \(Tabby's Place\) said:
--------------------[snip]--------------------
>I guess this could be true.  But I don't understand why someone would need
>an "easy" way to identify variables?  Why not an easy way to identify
>function names?  Or constants?
>
>In any case, I don't recall anyone complaining that they had trouble
>"identifying variables" in C, C++, Modula, Pascal, Java, etc.
--------------------[snip]-------------------- 

Quite right. But, having developed a couple of interpreters myself, I
assume there's some sound reason.

Think of how an interpreter works. It parses the sourcecode in realtime,
not as a compiler. People must _wait_, every time, until it is finished,
not only once like a compiler. Thus designers of interpreted languages like
something that can easily be distinguished, so you don't need to lookup a
lot of hash tables to identify a symbol, or to resolve amiguities.

That's why the '$' preceds a variable name. Simply said, when the parser
sees a '$', it knows which symbol table to look it up. If a token doesn't
have a '$', it can be found in the table of keywords of the language's
state machine.

Easy explanation, huh? Simple example: taken that a PHP application
consists of 1000 tokens, 200 of the tokens are variable names, and 800
non-variable tokens, the interpreter would either 200 times look up the
wrong symbol table (if it chooses to lookup the keywords first), or 800
times (if it looks up the entity table first).

Simply saves time...

-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to