Could .NET be parsed and evaluated at runtime

前端 未结 6 1514
轻奢々
轻奢々 2021-01-14 09:25

I thought it would be fun if I could write vb.net or c# code at runtime and the interpreter would automatically parse it like python does it, so I made a little program, whi

6条回答
  •  庸人自扰
    2021-01-14 10:07

    It can be, but it would be a lot of work.

    One way would be to write a parser + interpreter yourself. To create the parser, you'd need a grammar definition of the input language, such as C#. The C# grammar is very complex, mind you.

    Another way is to dynamically compile C# code. Here is an example of how to do that: http://www.voidspace.org.uk/ironpython/dynamically_compiling.shtml and http://blogs.msdn.com/b/saveenr/archive/2009/08/11/a-walkthrough-of-dynamically-compiling-c-code.aspx.

    Good luck!

提交回复
热议问题