Lex and Yacc in PHP
There's JLexPHP: https://github.com/wez/JLexPHP/blob/master/jlex.php
I've not used it, but there's this: http://pear.php.net/package/PHP_ParserGenerator , which creates a PHP Parser from a Lemon grammar. The project seems to be inactive though.
I also found this project: http://code.google.com/p/antlrphpruntime/ , which uses Antlr. Again inactive though.
Using lex and Yacc to parse php
See Zend/zend_language_parser.y .
Flex/Bison-like functionality within PHP
LIME Parser Generator for PHP:
Complete LALR(1) parser generator and
engine (like BISON or YACC) but it's
all done in PHP, and the input grammar
is easier and more maintainable. Write
your actions in PHP. Generate PHP
output code. Drive your parser with
PHP. Wanna make a language?
update:
Since I wrote the above, I see that there are some other tools for parser generation, announced here:
http://wezfurlong.org/blog/2006/nov/parser-and-lexer-generators-for-php/
Not sure if these are any better maintained now in 2014, but I know Wez Furlong, he was the original developer of PDO, and he is a very good developer.
Using Yacc and Lex to generate parse tree
The warning you get seems completely accurate:
F: | …
F
is a non-terminal; it has a type, and the first alternative is empty with no action. If a non-terminal has a production with no action, bison will automatically add the action $$ = $1
, but it can't do that for an empty production, so it complains.
I assume the |
in that line is a typo.
flex+bison in a php extension
I wouldn't use global variables, but use a more modern parser generator that is also reentrant. Look for instance how I've done it for the meta extension (I use a slightly changed lemon and re2c).
PHP Lexer and Parser Generator?
I'd propose to give ANTLR a try. ANTLRWorks might be helpful.
I wrote an LL(1) parser generator myself in pure PHP, since I wasn't aware of other PHP-based solutions.
Related Topics
Jetbrains Webide: PHP Variable Type Hinting
Using Comparison Operators in a PHP 'Switch' Statement
Get Code Line and File That's Executing the Current Function in PHP
How to Load View from Alternative Directory in Laravel 4
How to Use JSON.Stringify and JSON_Decode() Properly
Should I Mix Angularjs with a PHP Framework
Location for Session Files in Apache/Php
Pdo Multiple Fetching of Same Query
Have Trouble Installing PHPmyadmin on PHP7 Apache/2.4.7 (Ubuntu)
Using Zend Framework for Highload Projects
How to Pass Param from Controller to Layout in Yii2
Get String Between - Find All Occurrences PHP
How to Make Laravel Eloquent "In" Query
Troubleshooting "No Such File or Directory" When Running 'PHP App/Console Doctrine:Schema:Create'
How to Convert Date/Time from 24-Hour Format to 12-Hour Am/Pm