Reputation: 13325
i want to create a php parser.i was thinking of using lex/yacc for the task.
is that a good idea ? or there are better ways ?
where can i find an already made lex/yacc for php language. or at least the grammer ?
Upvotes: 1
Views: 1758
Reputation: 323
You can see the rphp_grammar.y in rphp_grammar's github rphp_grammar
Upvotes: 0
Reputation: 95420
See our PHP Front End. This is not built using traditional LEX and YACC, but has the advantage of a huge effort to define a robust parser, and hard knock testing over several years at this point. Using a fully elaborated grammar, it parses full PHP5 (that's hard, the language is poorly defined), including picking up all the details about interpolated string values, automatically builds ASTs, and can prettyprint ASTs back to completely valid PHP source text preserving layout, including comments.
Invariably there is life beyond parsing. and one needs tools to support the analysis or modification of the code to achieve the actual purpose. The engine underlying the PHP Front End, the DMS Software Reengineering Toolkit, provides the LEX- and YACC-like machinery we use and additionally provides the ability to procedurally navigate/inspect/modify the ASTs, provides source-to-source rewrite rules for pattern-matching and/or transformation of code, supports building of symbol tables, and provides a control and data flow analysis framework. This machinery makes it much easier to focus on getting the job done, rather than trying to implement such machinery ad hoc as you encounter the need. (DMS actually handles a wide variety of languages using front ends as means of integration).
Upvotes: 0