Re: GOTO operator
| From: | Alan Knowles | Date: | Mon, 02 Aug 2004 00:09:12 +0000 |
| Subject: | Re: GOTO operator | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-11801@lists.php.net to get a copy of this message | ||
if you have a look at a parser generated for PHP (eg. this - quite large file)
http://cvs.php.net/co.php/pear/HTML_Template_Flexy/Flexy/Tokenizer.php?r=1.51
The original Java/C# stuff does switch/case, In PHP due to the fact you have to evaluate each switch, it used to be quite slow,
I ended up replacing it with variable function calls, which even with PHP's penalty on calling functions was faster.
I suspect variable goto's would have made this code increadibly fast, in comparison.
You can do parsers using switch/case or $function, but unfortunatly they are slow..
Regards
Alan
David Chen wrote:
"Michael Walter" <cm@leetspeak.org> wrote in message news:410C4633.40804@leetspeak.org...-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.comAnother possibility, possibly more concise, would be to introduce a "scoped" keyword (or similar) in the spirit of "global": scoped $foo; might make $foo's destructor be called at the end of the current scope (whether left by a return statement or by an exception). Note that this only solves one part of the problem which could be summarized as "resource management". I'm not sure about generated code - did someone already post an example where goto might be useful in that case or did I miss that one?Considering that some don't accept exceptions to be a valid alternative to gotos, I don't think they'll accept a clearly OOP solution. And yes, I'm also still waiting for a code-generation example, but I guess we'll just assume that gotos are useful there (I use JavaCC, a Java-based top-down generator, so yes there's a lot of recursion but it looks pretty clean to me). David Chen