Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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