mrsuh/php-bison-skeleton 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mrsuh/php-bison-skeleton

最新稳定版本:1.2.0

Composer 安装命令:

composer require mrsuh/php-bison-skeleton

包简介

PHP skeleton for Bison

README 文档

README

A set of Bison skeleton files that can be used to generate a Bison parser written in PHP.

Requirements:

  • PHP >= 7.4
  • Bison >= 3.8

Installation

composer require --dev mrsuh/php-bison-skeleton

Usage

bison -S vendor/mrsuh/php-bison-skeleton/src/php-skel.m4 -o parser.php grammar.y

Posts

Docker

Example

grammar.y

%define api.parser.class {Parser} %token T_NUMBER %left '-' '+'  %% start:  expression { printf("%d\n", $1); } ;  expression:  T_NUMBER { $$ = $1; } | expression '+' expression { $$ = $1 + $3; } | expression '-' expression { $$ = $1 - $3; } ;  %% class Lexer implements LexerInterface {  private array $words;  private int $index = 0;  private int $value = 0;   public function __construct($resource)  {  $this->words = explode(' ', trim(fgets($resource))); } public function yyerror(string $message): void { printf("%s\n", $message); } public function getLVal() { return $this->value; } public function yylex(): int { if ($this->index >= count($this->words)) { return LexerInterface::YYEOF; } $word = $this->words[$this->index++]; if (is_numeric($word)) { $this->value = (int)$word; return LexerInterface::T_NUMBER; } return ord($word); } } $lexer = new Lexer(STDIN); $parser = new Parser($lexer); if (!$parser->parse()) { exit(1); }
bison -S vendor/mrsuh/php-bison-skeleton/src/php-skel.m4 -o parser.php grammar.y
php parser.php <<< "1 + 2" 3

See more examples in the folder

Tests

composer test

统计信息

  • 总下载量: 9.71k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 38
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 38
  • Watchers: 3
  • Forks: 2
  • 开发语言: M4

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固