PHP code example of edin / lexicon

1. Go to this page and download the library: Download edin/lexicon 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/ */

    

edin / lexicon example snippets


$tokens = Lexer::from(MyToken::class)->scan($source);
$node = Parser::fromTokens($tokens)->parse(MyNode::class);

#[OneOf([
    GroupedExpressionNode::class,
    NumberNode::class,
])]
interface PrimaryExpressionNode extends ExpressionNode
{
}

#[Terminal(MathToken::Number)]
final readonly class NumberNode implements PrimaryExpressionNode
{
    public function __construct(public Token $token)
    {
    }
}

#[Fold(
    operators: [MathToken::Plus, MathToken::Minus],
    operand: TermNode::class
)]
final readonly class ExpressionNode
{
    public function __construct(
        public Token $operator,
        public Node $left,
        public Node $right
    ) {
    }
}
bash
php examples/basic-scanner.php
php examples/json-scanner.php
php examples/xml-scanner.php
php examples/math.php