Login   Register  
PHP Classes
elePHPant
Icontem

File: src/eMacros/Program/Program.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Emmanuel Antico  >  eMacros  >  src/eMacros/Program/Program.php  >  Download  
File: src/eMacros/Program/Program.php
Role: Class source
Content type: text/plain
Description: Class source
Class: eMacros
PHP LISP language interpreter
Author: By
Last change:
Date: 2014-01-13 05:17
Size: 1,113 bytes
 

Contents

Class file image Download
<?php
namespace eMacros\Program;

use 
eMacros\Parser;
use 
eMacros\Environment\Environment;
use 
eMacros\GenericList;

abstract class 
Program {
    
/**
     * Program internal expressions
     * @var \eMacros\GenericList
     */
    
public $expressions;
    
    public function 
__construct($program) {
        
$this->expressions Parser::parse($programtrue);
    }
    
    public function 
offsetGet($offset) {
        return 
$this->expressions[$offset];
    }
    
    public function 
offsetExists($offset) {
        return 
array_key_exists($offset$this->expressions);
    }
    
    public function 
offsetSet($_$__) {
        throw new \
BadMethodCallException('Program object is immutable');
    }
    
    public function 
offsetUnset($_) {
        throw new \
BadMethodCallException('Program object is immutable');
    }
    
    public function 
getIterator() {
        return new \
ArrayIterator($this->expressions);
    }
    
    public function 
count() {
        return 
count($this->expressions);
    }
    
    public function 
executeWith(Environment $env, array $args) {
        
array_unshift($args$env);
        return 
call_user_func_array(array($this'execute'), $args);
    }
    
    public abstract function 
execute(Environment $env);
}
?>