php-go is a simple interpreter written in Go, inspired by PHP syntax. The project aims to recreate a subset of PHP, allowing you to interpret and execute PHP-like code directly in Go. The interpreter is built using ANTLR to generate the necessary parsers for processing the code.
Currently, php-go provides basic support for:
- Echo: Prints values, including strings, numbers, variables, and expressions.
- Operations: Performs arithmetic and comparison operations.
- Concatenation: Supports string concatenation using the
.operator. - Conditionals: Supports
if-elsestatements with boolean expressions. - Variables: Supports variables declarations.
- Go 1.x or higher installed.
- ANTLR installed for generating parsers. For more information, visit ANTLR's official website.
-
Clone the repository:
git clone https://github.com/xoesae/php-go.git cd php-go -
Build the project: Run the following command to build the code:
go build
-
Run the interpreter: After building, use the command below to run the PHP-like code from an input file:
php-go path/to/file.php
Example input:
You can find several examples in the
examplesfolder. You can run them using:php-go examples/echo.php
Here are some example inputs you can test, located in the examples folder:
// Example 1: Simple echo
echo "Hello, World!";
// Example 2: Variables
$name = "Carlos";
echo $name;
// Example 3: Arithmetic operations
echo 1 + 1;
echo 1.5 + 1;
echo 3+3==6;
echo 3+3==7;
// Example 4: String concatenation
echo "Carlos " . "Carlos";
// Example 5: Conditionals
if (true) { echo "TRUE"; } else { echo "FALSE"; }
if (false) { echo "TRUE"; } else { echo "FALSE"; }- Fork the repository.
- Create a branch for your feature (
git checkout -b feature-name). - Commit your changes (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature-name). - Open a pull request.