phpython Code
a python interpreter written in php
Status: Pre-Alpha
Brought to you by:
francescobianco
--- a/trunk/python/python.lib.php +++ b/trunk/python/python.lib.php @@ -7,19 +7,33 @@ $parser = new parse_engine(new python()); function python_eval($pycode) { + global $parser; - $line = $pycode; $codeline = 1; - if (!strlen($line)) return; + if (!strlen($pycode)) return; try { $parser->reset(); - foreach(python_tokenize($line) as $token) { - $parser->eat($token["name"], $token["value"]); - if ($token["name"] == "NEWLINE") { + $tokens = python_tokenize($pycode); + $alltok = count($tokens); + $cursor = 0; + + while($cursor < $alltok) { + $token0 = $tokens[$cursor]; + $token1 = isset($tokens[$cursor+1]); + + dump_token($token0); + + $parser->eat($token0["name"], $token0["value"]); + + if ($token0["name"] == "NEWLINE") { $codeline++; } + + $cursor++; } + $parser->eat_eof(); + } catch (parse_error $e) { echo '<pre>'; echo $e->getMessage(), "\nLine: $codeline;", "\n";