Created
March 21, 2021 13:09
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class Node {} | |
class Calculator extends Node { | |
public function __construct(public array $statements){} | |
} | |
class Add extends Node { | |
public function __construct(public Node $left, public Node $right){} | |
} | |
class Substract extends Node { | |
public function __construct(public Node $left, public Node $right){} | |
} | |
class Minus extends Node { | |
public function __construct(public Node $node){} | |
} | |
class Number extends Node { | |
public function __construct(public float $value){} | |
} | |
class Assign extends Node { | |
public function __construct(public string $variable, public Node $node){} | |
} | |
class Get extends Node { | |
public function __construct(public string $variable){} | |
} | |
$firstStatement = new Assign('foo', new Add(new Number(1), new Number(5))); | |
$secondStatement = new Substract(new Number(100), new Minus(new Get('foo'))); | |
$calculator = new Calculator([$firstStatement, $secondStatement]); | |
var_dump($calculator); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment