Lex and Yacc in PHP

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



Leave a reply



Submit