Writing a mini-language

后端 未结 9 1829
南方客
南方客 2021-01-31 23:40

I have an application that needs to allow users to write expressions similar to excel:

(H1 + (D1 / C3)) * I8

and more complex things like

If(H1 = \'True

9条回答
  •  一生所求
    2021-02-01 00:11

    I would recommend the book Constructing Little Languages. It takes you through many compiler basics needed for completing this task properly.

    You've brought up the fact that regular expressions will not work unless you have some stringent limits on your language. Like others have said, a Recursive Descent Parser will do the trick.

    The choice next would be whether to use a Parser Generator like ANTLR, or to write one from scratch.

提交回复
热议问题