1. Go to this page and download the library: Download procionegobbo/polygen-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
procionegobbo / polygen-php example snippets
Polygen\Polygen;
$grammar = 'S ::= hello world | goodbye world ;';
$generator = new Polygen($grammar);
echo $generator->generate(); // Output: "hello world" or "goodbye world"
$grammar = 'Greeting ::= hello | hi | hey ;
Recipient ::= world | there ;
S ::= Greeting Recipient ;';
$generator = new Polygen($grammar);
echo $generator->generate(); // "hello world", "hi there", etc.
$grammar = 'S ::= hello [beautiful] world ;';
$generator = new Polygen($grammar);
// Generates either "hello world" or "hello beautiful world"
echo $generator->generate();
$grammar = 'S ::= \ hello ^ man ;';
$generator = new Polygen($grammar);
echo $generator->generate(); // "Hello man"
// ^ capitalize next word
// ^ no space (concatenation)
// Definition (re-evaluate each time)
$grammar = 'Color ::= red | blue | green ;
S ::= Color Color ;';
$generator = new Polygen($grammar);
echo $generator->generate(); // e.g., "red blue" or "green green"
// Assignment (memoize result)
$grammar = 'Color := red | blue | green ;
S ::= Color Color ;';
$generator = new Polygen($grammar);
echo $generator->generate(); // Always "color color" with the same color twice