none
Tools, books for creating a .Net compiler for a new custom language. RRS feed

  • Question

  • Can anybody list any useful public tools and books that can serve as a starting point for creating a new .Net langauge?

    I'm only trying to get a feel for the scope/scale of this at this stage, not comitted to actually doing it until I do more cost/benefit stuff.

     

    Thx

    Cap'n

     

    Friday, July 15, 2011 12:50 PM

Answers

All replies

  • You may want to have a look at the CompilerServices namespace.

    http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices(v=VS.100).aspx

    It is full of classes that are used to compile .NET languages.

    • Marked as answer by Paul Zhou Monday, July 25, 2011 7:08 AM
    Friday, July 15, 2011 1:05 PM
    Moderator
  • No, no, no...

     

    A new .Net language, not compiler.

    I', also interested.

     

    Sunday, July 17, 2011 4:22 PM
  • No, no, no...

     

    A new .Net language, not compiler.

    I', also interested.

     


    Yes, yes, yes! :) The CLR only understands IL. The compiler takes the source code and compiles it to IL so the CLR understands it.

    If you want to create a new language you need to create a compiler for it. At least if you wish for it to be used to create real applications...

    Monday, July 18, 2011 8:59 AM
    Moderator
  • What if my language does not have more features than an existing .Net language has.

    I mean, every app in my Swave (thats what I call it) language can be converted into C#. There are no programming elements, structures, relationships or whatever can a programming language have that can't be converted to corresponding c# code.

    I know what IL is, but to compile to IL requires a huge knowledge of the CLR, advanced memory operations... I have read few books about it, but it's to big for me to create a compiler that maintains the IL correctly.

    So I would want to convert to C# and use the CSharpCodeProvider or what ever there is to compile C# to IL.


    Tuesday, July 19, 2011 3:48 PM
  • You're right, no need for compiler services in case of just translating own .NET language to existing one.

    Good luck with your parser.

    Tuesday, July 19, 2011 4:23 PM
    Moderator
  • One more question

     

    I was thinking:

    My language is compatible with C# in 100%, so for every line like this:

    Workspace.GetAllRunningApplications(Machines: ThisMachine, IncludeBackgroundApplicationsAndServices: Yes, IncludeTerminalApplications: Yes)

    Workspace.RequireScreenAppearanceWithLock(Lock: Application.ScreenLockID) 


    I write in c# file myprogram.cs this:

    Workspace.GetAllRunningApplications(WorkspaceMachines.ThisMachine, true, true);

    Workspace.RequireScreenAppearanceWithLock(Application.ScreenLockID);

    and I compile it.

     

    And so I ask:

    Instead of writing to a file the code (and making the c# compiler parse it again later) could I make something like this (imaginary):

    myCodeToCompile.AddMethodCallStatementWithParamethers("Workspace.GetAllRunningApplications", new object[2] {true, true});

    myCodeToCompile.AddMethodCallStatementWithParamethers("Workspace. RequireScreenAppearanceWithLock", new object[1] {Application.ScreenLockID});

     

    The statements would be parsed already and it would fasten up compilation time. Are their any methods of doing something like this? I have browsed some websites but nothing interesting had found. All I need to know is a library name, a class name or any word that would help me do this.

    Friday, July 22, 2011 5:52 PM
  • Take a look at this article from codeproject

    http://www.codeproject.com/KB/recipes/matheval.aspx

     

     


    Friday, July 22, 2011 5:59 PM
    Moderator
  • Take a look at this article from codeproject

    http://www.codeproject.com/KB/recipes/matheval.aspx

     

     


    You gave me an example of how to dynamically run code in runtime. The eval statement must be in C#.

    I mean something like adding statements to the C# parser when I parse the code. Something like a stream: read a bit, write a bit...



    • Proposed as answer by Jacob Brown Thursday, July 28, 2011 10:33 AM
    • Unproposed as answer by Jacob Brown Thursday, July 28, 2011 10:33 AM
    Friday, July 22, 2011 6:45 PM
  • What stops you from writing the compiled code to an assembly instead of running it?
    • Proposed as answer by Jacob Brown Thursday, July 28, 2011 10:33 AM
    • Unproposed as answer by Jacob Brown Thursday, July 28, 2011 10:33 AM
    Friday, July 22, 2011 7:18 PM
    Moderator
  • No, no, no.

    When the user clicks the Run button (Build And Run), I parse the Swave code into C#. I write it in a file. I run CSharpCodeProviders to compile. I run the assembly. This works OK.

    But I'm asking: You really have to write to a file, then let the compiler read the file... Some bigger source codes could not fit in memory (keeping them in string format).

    Thanks for overall help.


    • Proposed as answer by Jacob Brown Thursday, July 28, 2011 10:33 AM
    • Unproposed as answer by Jacob Brown Thursday, July 28, 2011 10:33 AM
    Sunday, July 24, 2011 10:33 AM
  • Hi, Jacob,

    Maybe you can use NRefactory (http://wiki.sharpdevelop.net/NRefactory.ashx)? As far as I can see, you wuld only need a parser for your language, and get the conversion to C# for free.

    Or you use the mono compiler and change their c# parser to parse your language.

    Or you use dynamic code generation as it is used by IronPython. (The most work, but no need to write any files on-disk.)

     

    HTH,
    Markus


    • Proposed as answer by Jacob Brown Thursday, July 28, 2011 10:33 AM
    • Unproposed as answer by Jacob Brown Thursday, July 28, 2011 10:33 AM
    Sunday, July 24, 2011 12:15 PM
  • Thanks
    • Proposed as answer by Jacob Brown Thursday, July 28, 2011 10:33 AM
    Monday, July 25, 2011 7:14 PM