Menu

[r5]: / trunk / python / python.lib.php  Maximize  Restore  History

Download this file

27 lines (22 with data), 604 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
require_once("../lime/parse_engine.php");
require_once("python.class");
require_once("python-tokenizer.php");
require_once("python-interface.php");
$parser = new parse_engine(new python());
function python_eval($pycode) {
global $parser;
$line = $pycode;
if (!strlen($line)) return;
try {
$parser->reset();
foreach(python_tokenize($line) as $t) {
if (is_numeric($t)) $parser->eat('num', doubleval($t));
else if (ctype_alpha($t)) $parser->eat('var', $t);
else $parser->eat("'$t'", null);
}
$parser->eat_eof();
} catch (parse_error $e) {
echo $e->getMessage(), "\n";
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.