Question

The question is very straightforward: Is it possible to parse PHP using PEG? I want to use a PEG parser-generator to parse PHP. Please kindly advise. Thank you!

Was it helpful?

Solution

You can make most parser technologies parse most languages, with sufficient effort.

Whether PEG will parse PHP without a lot of effort is a different question.

AFAIK, PHP itself uses Bison (LALR) so I assume PEG will likely handle the grammar supplied by the PHP distribution or something similar. And if you're going to use the PHP distribution, why not just use their supplied parser?

If you don't use the PHP distribution, your problems with parsing PHP are likely to be hard because you'll have to guess the language syntax from the online reference manual, (I've been there, and done that) which is frankly one of the worst ways to define a langauge I've ever seen: all it is is a bunch of examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top