예제 #1
0
 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;
 }
예제 #2
0
파일: cain.php 프로젝트: jimbonator/cain
/**
 * 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();
}
예제 #3
0
 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);
 }