Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I were going to make a C# compiler today, here's what I would <del>do</del> try as a first attempt:</p> <ol> <li>Start with the ANTLR C# 3 target (of course I'm biased here - seriously you can use either the CSharp2 or CSharp3 target).</li> <li>Get Visual Studio 2010 with the .NET Framework 4. The key here is .NET 4 and it's sweet new expression trees.</li> <li>Build a basic combined parser. Put as little logic in the parser as absolutely possible. It should have few (if any) actions, and the output should be an undecorated AST that can be walked with LL(1) walker.</li> <li>Build a tree grammar to walk the tree and identify all declared types. It should also keep the <code>member_declaration</code> sub-trees for later use.</li> <li>Build a tree walker that walks a single <code>member_declaration</code> and adds the member to the <a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.typebuilder%28VS.100%29.aspx" rel="nofollow noreferrer"><code>TypeBuilder</code></a>. Keep track of the method bodies but don't deep-walk them yet.</li> <li>Build a tree walker that walks the body of a method. Generate an <a href="http://msdn.microsoft.com/en-us/library/bb335710%28VS.100%29.aspx" rel="nofollow noreferrer"><code>Expression&lt;TDelegate&gt;</code></a> matching the method, and use <del>the <a href="http://msdn.microsoft.com/en-us/library/dd728258%28VS.100%29.aspx" rel="nofollow noreferrer"><code>CompileToMethod</code></a> method</del> my own API (see Pavel's and my comments) to generate the IL code.</li> </ol> <p>If you do things in this order, then when you are finally parsing the expressions (method bodies, field initializers), you can use the <code>string</code> parameterized methods <a href="http://msdn.microsoft.com/en-us/library/bb351107%28VS.100%29.aspx" rel="nofollow noreferrer">like this one</a> in the <a href="http://msdn.microsoft.com/en-us/library/system.linq.expressions.expression%28VS.100%29.aspx" rel="nofollow noreferrer"><code>Expression</code></a> class to save work resolving members.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload