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