Created
March 21, 2021 13:09
-
-
Save lorisleiva/2f92358b170b05b4a51082422b34df64 to your computer and use it in GitHub Desktop.
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