Skip to content

Instantly share code, notes, and snippets.

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