Hello guys this is me Genesis and I am going to teach you how to create a Programming Language using C#.

Well, the tool we are going to use is "Microsoft Visual C#" and download it in the Internet if you didn't have it yet.

Well, I am playing the codes just to put the following codes:
Console.ReadLine();
But I haven't see to it that I can't post that command in my project so let's get started.

Step 1: Creating a console application project

Here is the following step to create a Console Application project:
1. Go to File -> New Project.
2. Make sure you click "Console Application" and name whatever you want.
3. Click OK.

step 2: start typing the codes to create the project!

Here's what you see once you create your project:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Eagle_Script
{
 class Program
    {
      static void Main(string[] args)
      {
      }
  }
}
Looks difficult where to start huh. Well, the "namespace Eagle_Script" in the codes is the name of the project that you have typed to create the project.

Add these codes just below "using System.Text;":
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
Well, we're not getting closer but we are getting into it.

Below the second "{" which is just above the "static void Main(string[] args)", put in these codes:
static AssemblyName an;
static AssemblyBuilder ab;
static ModuleBuilder mb;
static TypeBuilder tb;
static _AppDomain ad;
static MethodBuilder meb;
static ILGenerator il;
OK so we are getting this clear so I want you to add these codes under the third "{":
ad = AppDomain.CurrentDomain;
an = new AssemblyName("lol");
ab = ad.DefineDynamicAssembly(an, AssemblyBuilderAccess.Save);
mb = ab.DefineDynamicModule("Lol", "idk.exe");
meb = tb.DefineMethod("main", MethodAttributes.Public | MethodAttributes.Static);
il = meb.GetILGenerator();
an.Name = "MyApp";
ab.SetEntryPoint(meb);

StreamReader sr = new StreamReader(args[0]);
string Code = sr.ReadToEnd();

//The codes below is the creation of our own syntax in its own command.
    foreach (string cmd in Code.Split('\n'))
    {
      if (cmd.StartsWith("print"))
      {
          il.Emit(OpCodes.Ldstr, cmd.Substring(6));
          il.Emit(OpCodes.Call, typeof(System.Console).GetMethod("Write", new System.Type[] { typeof(string) }));
      }
      if (cmd.StartsWith("println"))
      {
          il.Emit(OpCodes.Ldstr, cmd.Substring(8));
          il.Emit(OpCodes.Call, typeof(System.Console).GetMethod("WriteLine", new System.Type[] { typeof(string) }));
        {
    }
  }
  il.Emit(OpCodes.Ret);
  tb.CreateType();
  ab.Save(Path.GetFileNameWithoutExtension(args[0]) + ".exe");
OK, we're done! It is time to publish our work.

STEP 3: PUBLISH THE PROGRAMMING LANGUAGE

To publish your software, go to Build -> Publish in the Menu bar and publish according to the requirements.

step 4: test it!

In your notepad, type this:
print Hello
print World
println Lol!
Save it, then drag into the compiler which is in type .exe. that you have created (in the file of your programming language).
 


Comments

Maria
01/04/2013 9:25pm

can i add more commands and syntax in my programming language 'coz i quite know this c# hehehehehe...

Reply
01/04/2013 9:28pm

Hi Maria,

We are researching for your request and we are hoping to post it by the end of January. We are hoping for more posts in a while.

Thanks,
DgBlogs

Reply
Pantomchap
05/18/2013 7:55pm

I get this exception: Object reference not set to an instance of an object. The exception was at line 26

Reply
05/19/2013 1:45am

Are you sure you followed all the instructions?

Reply

Your comment will be posted after it is approved.


Leave a Reply

    Translate

    Author

    David Genesis C. Pedeglorio, the founder of this site. David Genesis C. Pedeglorio is from the Philippines. Studying Web designer course from AMA. He will complete the course by April 2013. He is an animator, web designer, software programmer and a computer games creator.

    Categories

    All
    Dreamweaver
    Flash
    Microsoft Programs
    Photoshop
    Programming Languages

    recent forums