Could .NET be parsed and evaluated at runtime

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, which would do something similar. Basically it looks like this:

InputArgs = Console.ReadLine()
ParseInput(InputArgs.Split(" "))

Private Sub ParseInput(Args as List(Of String), Optional TempArgs as List(Of String))
Dim arg as string = Args(0)
If arg = ".." then
 ...
elseif arg = ".." then
 ...
end if
End Sub

I know it's not a good system, but it show's the basics. So my question is: Is it possible to make vb.net or c# like python - interpreted at runtime?

Answers


This already exists in a fair number of shapes and forms:

Mono.CSharp

Mono has the Mono.CSharp assembly, which you can reference to do whatever CSharp.exe (A C# 'interpreter' or interactive shell, if you will) can do:

void ReadEvalPrintLoopWith (ReadLiner readline)
{
    string expr = null;
    while (!InteractiveBase.QuitRequested){
            string input = readline (expr == null);
            if (input == null)
                return;

            if (input == "")
                continue;

            expr = expr == null ? input : expr + "\n" + input;

            expr = Evaluate (expr);
    } 
}

Needless to say this works on MS.Net too (of course, that's the point about portable .Net).

Full sources here on github - just as the rest of Mono, in fact.

DLR

Several DLR languages have been implemented, including but not limited to

It will allow you to evaluate python/ruby code on the fly in the .NET framework.

Roslyn

Microsoft has published Roslyn as a CTP (preview). It can basically do the same stuff as the Mono REPL (first item), and (much) more. But it is a preview still.


Need Your Help

Passing dynamic array of structs to GPU kernel

c++ cuda structure dynamic-memory-allocation

I try to pass my dynamic array of structs to kernel but it doesn't works. I get - "Segmentation fault (core dumped)"

How can you build a REST client, given that the client should have no prior knowledge excepting a starting url?

java flash rest web-applications client

I've started work on a pre existing REST application and am having trouble understanding how one would go about making a RESTful client?