PHP Classes

File: src/eMacros/Literal.php

Recommend this page to a friend!
  Classes of Emmanuel Antico   eMacros   src/eMacros/Literal.php   Download  
File: src/eMacros/Literal.php
Role: Class source
Content type: text/plain
Description: Class source
Class: eMacros
PHP LISP language interpreter
Author: By
Last change:
Date: 10 years ago
Size: 785 bytes
 

Contents

Class file image Download
<?php
namespace eMacros;

class
Literal implements Expression {
   
/**
     * Literal value
     * @var mixed
     */
   
public $value;

    public function
__construct($value) {
        if (!
in_array(gettype($value), array('integer', 'double', 'string'))) {
            throw new \
UnexpectedValueException(sprintf("Literal: Unexpected value of type '%s'.", gettype($value)));
        }
       
       
$this->value = $value;
    }

    public function
evaluate(Scope $scope) {
        return
$this->value;
    }
   
    public function
isInteger() {
        return
is_int($this->value);
    }
   
    public function
isReal() {
        return
is_float($this->value);
    }
   
    public function
isString() {
        return
is_string($this->value);
    }
   
    public function
__toString() {
        return
var_export($this->value, true);
    }
}
?>