What is a good parser generator for php?

后端 未结 4 774
清酒与你
清酒与你 2020-11-29 09:31

I need to parse a small \'mini language\' which users can type on my site. I was wondering what the counterparts of lex and jacc or antlr are for the world of php.

4条回答
  •  醉酒成梦
    2020-11-29 10:12

    I advise you to write your own parser, as it is quite easy today.

    The easiest way to do so would be in my opinion to create one class for every syntax type possible (expression, test, loop, etc.).

    Then in each class, code the following methods:

    • one method to determinate from a string if the string is of the given type (a+b is of type 'expression', if(b) is not)
    • one method to "run" this type (a+b will return a->run() + b->run(), and a->run() will return a value)

提交回复
热议问题