private static function cl($stream = null) { global $LIB; $lib = new CainTokenizer(null, $LIB); $lib->tokenize(); $src = null; if ($stream) { $src = new CainTokenizer(null, $stream); $src->tokenize(); } $ci = new CainInterpreter(); $roots = $ci->parse($lib); if ($src) { $roots = $ci->parse($src); } return $roots; }
/** * Tokenize, parse, and execute a Cain program. * * $file should be an absolute file path or URI of the source code, or null to indicate in-memory * source. * * $stream should be a stream resource for the $file or a string of the entire source code. * * In both cases, the source should hold a Program instance with a run message handler, the entry * point for program start. */ function cain($file, $stream) { if ($file === null) { $file = '(memory)'; } $ct = new CainTokenizer($file, $stream); $ct->tokenize(); $ci = new CainInterpreter($ct); $roots = $ci->parse(); $ce = new CainExecutive($roots); return $ce->run(); }
public function testMultipleStreams() { $ci = new CainInterpreter(); $ct1 = new CainTokenizer(null, 'type Any { }'); $ct1->tokenize(); $roots = $ci->parse($ct1); $ct2 = new CainTokenizer(null, 'type String { Any test := {} }'); $ct2->tokenize(); $roots = $ci->parse($ct2, $roots); $this->assertTrue($roots->get_container_by_name('Any') !== null); $this->assertTrue($roots->get_container_by_name('String') !== null); }