REPL for C#

Don Box wrote a little program which gives you a little command line c# intepreter. Unfortunately he wrote it for .net 2 beta so I tried to rewrite it for .net 1.1.

Things went fairly well, and I have a basic interpreter, unfortunately I think due to the lack of anonymous function support the Invoke command doesn’t work.

You simply need to remove the System.Collections.Generic line from the top (don’t know why its there anyway) and change the following line:

ICodeCompiler compiler = CodeDomProvider.CreateProvider(“C#”).CreateCompiler();

becomes

ICodeCompiler compiler = new Microsoft.CSharp.CSharpCodeProvider().CreateCompiler();

If anyone has any ideas on how to get support for methods and other features (like a simple for loop for example) that would be great.

One Reply to “REPL for C#”

  1. try code below.
    The usage is > { for (int i = 0 ; i++ ; i “);
    Console.Out.Flush();
    string expr = Console.ReadLine();
    if (expr == null)
    break;
    try
    {
    string result = StringEval(expr , false );
    Console.WriteLine(result);
    }
    catch (TargetInvocationException ex)
    {
    Console.WriteLine(ex.InnerException.GetType().Name + “: ” + ex.InnerException.Message);
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.GetType().Name + “: ” + ex.Message);
    }
    }

    }
    }
    }

Comments are closed.