{"id":19033150,"url":"https://github.com/mrsuh/php-bison-skeleton","last_synced_at":"2025-04-07T12:09:02.141Z","repository":{"id":127505601,"uuid":"611228536","full_name":"mrsuh/php-bison-skeleton","owner":"mrsuh","description":"PHP skeleton for Bison","archived":false,"fork":false,"pushed_at":"2024-11-23T09:34:59.000Z","size":170,"stargazers_count":37,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T11:04:09.435Z","etag":null,"topics":["bison","parser-generator","php","php-bison-skeleton","skeleton"],"latest_commit_sha":null,"homepage":"https://mrsuh.com/projects/php-bison-skeleton/","language":"M4","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrsuh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-08T11:47:36.000Z","updated_at":"2025-01-03T17:32:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"06782ac8-6987-46b9-baab-27a9d35f2c03","html_url":"https://github.com/mrsuh/php-bison-skeleton","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"43454eac0c86cb614aae67df350907d0baa90c94"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsuh%2Fphp-bison-skeleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsuh%2Fphp-bison-skeleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsuh%2Fphp-bison-skeleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsuh%2Fphp-bison-skeleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrsuh","download_url":"https://codeload.github.com/mrsuh/php-bison-skeleton/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648978,"owners_count":20972945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bison","parser-generator","php","php-bison-skeleton","skeleton"],"created_at":"2024-11-08T21:35:51.529Z","updated_at":"2025-04-07T12:09:02.123Z","avatar_url":"https://github.com/mrsuh.png","language":"M4","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP skeleton for Bison\n\n![](https://github.com/mrsuh/php-bison-skeleton/actions/workflows/tests.yml/badge.svg)\n![](https://img.shields.io/github/license/mrsuh/php-bison-skeleton.svg)\n![](https://img.shields.io/github/v/release/mrsuh/php-bison-skeleton)\n\nA set of Bison skeleton files that can be used to generate a Bison parser written in PHP.\n\n## Requirements:\n* PHP \u003e= 7.4\n* Bison \u003e= 3.8\n\n## Installation\n```bash\ncomposer require --dev mrsuh/php-bison-skeleton\n```\n\n## Usage\n```bash\nbison -S vendor/mrsuh/php-bison-skeleton/src/php-skel.m4 -o parser.php grammar.y\n```\n\n## Posts\n* [PHP Skeleton for Bison](https://mrsuh.com/articles/2023/php-skeleton-for-bison/)\n* [AST parser with PHP and Bison](https://mrsuh.com/articles/2023/ast-parser-with-php-and-bison/)\n* [Nginx parser with PHP and Bison](https://mrsuh.com/articles/2023/nginx-parser-with-php-and-bison/)\n* [JSON parser with PHP and Bison](https://mrsuh.com/articles/2023/json-parser-with-php-and-bison/)\n\n## Docker\n* [Bison docker image](https://github.com/mrsuh/docker-bison)\n\n## Example\n\n`grammar.y`\n```php\n%define api.parser.class {Parser}\n%token T_NUMBER\n%left '-' '+'\n\n%%\nstart:\n  expression                       { printf(\"%d\\n\", $1); }\n;\n\nexpression:\n  T_NUMBER                         { $$ = $1; }\n| expression '+' expression        { $$ = $1 + $3;  }\n| expression '-' expression        { $$ = $1 - $3;  }\n;\n\n%%\nclass Lexer implements LexerInterface {\n    private array $words;\n    private int   $index = 0;\n    private int   $value = 0;\n\n    public function __construct($resource)\n    {\n        $this-\u003ewords = explode(' ', trim(fgets($resource)));\n    }\n\n    public function yyerror(string $message): void\n    {\n        printf(\"%s\\n\", $message);\n    }\n\n    public function getLVal()\n    {\n        return $this-\u003evalue;\n    }\n\n    public function yylex(): int\n    {\n        if ($this-\u003eindex \u003e= count($this-\u003ewords)) {\n            return LexerInterface::YYEOF;\n        }\n\n        $word = $this-\u003ewords[$this-\u003eindex++];\n        if (is_numeric($word)) {\n            $this-\u003evalue = (int)$word;\n\n            return LexerInterface::T_NUMBER;\n        }\n\n        return ord($word);\n    }\n}\n\n$lexer  = new Lexer(STDIN);\n$parser = new Parser($lexer);\nif (!$parser-\u003eparse()) {\n    exit(1);\n}\n```\n\n```bash\nbison -S vendor/mrsuh/php-bison-skeleton/src/php-skel.m4 -o parser.php grammar.y\n```\n\n```bash\nphp parser.php \u003c\u003c\u003c \"1 + 2\"\n3\n```\n\nSee more examples in the [folder](./examples)\n\n### Tests\n```bash\ncomposer test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrsuh%2Fphp-bison-skeleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrsuh%2Fphp-bison-skeleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrsuh%2Fphp-bison-skeleton/lists"}