Compiler compiler in C#

后端 未结 7 985
遥遥无期
遥遥无期 2021-02-03 13:28

I\'m looking for a customizable parser and/or lexer that can allow me to build a custom syntax checker in C#. Essentially the user will enter code a line of code (custom), and t

7条回答
  •  北恋
    北恋 (楼主)
    2021-02-03 13:54

    If what the user is entering is a line of code corresponding to traditional expressions, you can hand-code a recursive descent parser for this in a few hours max and be done with it.

    If your input is a fragment of a complex language (e.g., you want to accept a line of C# code) you'll need a much strong parser and a parser generator is recommended.

    However, you'll find that most parser generators do not offer you a good way to parse a piece of the language that you define, but you can hack you way around that by defining the root grammar rule to mention the nonterminals that correspond to the "lines" that you are willing to accept.

提交回复
热议问题