This is a PHP-subset compiler
- Required open tag:
<?php - Literals:
int,float,string - Variables:
$name = expression; - Constants:
const NAME = expression; - Expressions: variable/const references, unary minus,
+ - * /, parentheses - Function declarations:
function name($a, $b) { return ...; } - Typed function args:
function name(int $a, float $b, string $c) { ... } - Classes and methods:
class Name { public function f(...) { ... } } - Visibility modifiers on methods:
public,private,protected - Constructors:
__construct(...) - Object instantiation and method calls:
new Name(...),$obj->method(...) - Named arguments for user function/method/constructor calls:
f(a: 1, b: 2) - Class type hints in function/method arguments:
function use(Box $b) { ... } - Interfaces and traits:
interface,trait,implements, classuse TraitName; - Inheritance: class
extendsand interfaceextends - File inclusion:
include,include_once,require,require_once- Includes are resolved relative to the current file path at compile time.
- Path expressions can be compile-time strings:
"x.php",$var, or const identifiers. require*fails compilation when a file is missing.include*skips missing files (no warning output yet).
- User-defined function calls:
name(1, 2) - Builtin function calls:
echo(...),print(...)
ast/AST node definitionslexer/tokenization for PHP subset syntaxparser/Pratt parsercode/bytecode opcodes and instruction encodingcompiler/AST -> bytecode compilervm/bytecode virtual machine runtimeobject/runtime object/value typesrepl/interactive shellexamples/sample PHP programseval/,bench/placeholders for future parity with Monkey layout
cd /home/ross/projects/pogo
go test ./...
go run . examples/math.php
go run . examples/classes_public_private.php
go run . examples/classes_protected.php
go run . examples/classes_type_hints.php
go run . examples/interfaces_traits.php
go run . examples/extensions.php
go run . examples/includes_main.php
go run . examples/includes_variable_main.phpThis compiles a .php source file to bytecode, generates a temporary runner project at
/tmp/pogo-<unixms>, embeds the bytecode with go:embed, and builds one standalone binary.
cd /home/ross/projects/pogo
go run . build examples/math.php -o ./math.bin
./math.binOptions:
-o <path>: output binary path (default: input basename)--keep-temp: keep generated/tmp/pogo-<unixms>runner project
consts:
RATE = 1.5
vars:
$base = 10
$total = 15
- Add comparisons/conditionals (
if,===, etc.). - Add control flow (
while,for,break,continue). - Expand builtins and string/array operations.
- Add dynamic include paths and runtime include return values.