Click here to Skip to main content
15,913,090 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
I want to know how to create a simple programming languge.For example, I want to create a programming language called "Simple1." All codes you enter in a textbox will be converted to c#.My IDE is Visual Studio 2010 Proffesional...
Posted
Comments
S@53K^S 12-Apr-12 9:19am    
Idea is good but that problem is that you are ultimately using C#/.NET for the execution of the code and getting it converted to machine instruction.
Shahin Khorshidnia 12-Apr-12 11:24am    
A compiler doesn't necessarily translate a programming language to native code. it can just translate a computer language to another one (C# for example)
BobJanova 12-Apr-12 11:04am    
You need to actually define the language first. I'm not sure you really understand what you're asking ...

step1:create a mapping table from your language to C#(Just include key words).
step2:convert the text in textbox to C# by the mapping table.
step3:use CodeDom (or Emit) to compile and run the C# code.
 
Share this answer
 
v2
That isn't really a question we can answer.
It is seriously complex. For example, have a look at this: VB6 C# VB Code Converter[^] It may start to give you a clue what you would need to do.

And if you really do try to do this project, don't go to C# - go to IL and make your language interoperable with any other .NET language. It would probably be easier, and it would certainly be more useful. There is an article on this here: http://msdn.microsoft.com/en-us/magazine/cc136756.aspx[^]
 
Share this answer
 
Comments
Shahin Khorshidnia 12-Apr-12 11:28am    
Good link (http://msdn.microsoft.com/en-us/magazine/cc136756.aspx[^])
+5
Andreas Gieriet 14-Apr-12 15:52pm    
Why not generate C#?
I remeber the old days where C-compilers translated into assembler text and then only ran the assembler to translate into binary code.
Or C++ compilers: C++ --> C --> Ass --> Bin.

For a novice in compiler construction, it might help to write as an early execise a translator from "Simple1" into C#. Reasoning: I assume the OP knows C#, so he can focus on the first stages: scanner, parser, AST, C# generator. Learning IL is quite a challenge, I would say.

Andi
Hello,

The name of an application that transforms a source code string into another programming language is "compiler".

Start with these:
Automata theory
TEACHING LANGUAGE THEORY AND AUTOMATA
Basics of Compiler Design

I like it: Compiler Design

After those, I think you will be able to find the way.

====
Of course OriginalGriff has recommended useful links too.
 
Share this answer
 
v6
Comments
Hysen Ndregjoni 12-Apr-12 12:59pm    
i know that it is a coompiler,but thanks
Shahin Khorshidnia 12-Apr-12 13:50pm    
Yes, of course you knew that was a compiler but you already know what you are supposed to do for starting. And you're welcome!
Hey!

I am a programming language writer and I have been doing it for about 2 years now. I just want to show you that making a programming language isn't as hard as everyone is telling you, I am going to teach you how to make a very simple programming language write now!

here is the code:

C#
string code = @"
print Hello World
read
";

foreach (string a in code.Split('\n'))
{
    if (a.Startswith("print "))
    {
        Console.Write(a.Substring(6));
    }
    else if (a == "read")
    {
        Console.Read();
    }
}


this is probably the most basic programming language that someone can create, but it is the basis of how programming languages are made.

There is the first bit; the code, this doesn't need much explaining, this is just the code that is going to run through the scanner and parser, this is one way of writing code, but to get code from outside the .exe file, use a streamreader class that can get to it. To use that, change the code to look like this:

XML
<pre lang="c#">
StreamReader sr = new StreamReader(args[0]);
string code = sr.ReadToEnd();

foreach (string a in code.Split('\n'))
{
    if (a.Startswith("print "))
    {
        Console.Write(a.Substring(6));
    }
    else if (a == "read")
    {
        Console.Read();
    }
}

</pre>


of course put this into the main void and it will work. The way to run the code is by dragging a file with the text in it onto the .exe file and it will run.

The second part is the Scanner. The scanner is the Foreach statement, not what's inside of it. The foreach statement turns your code into tokens, called 'a'. It splits the code at every new line, so you don't need those ';' they have in professional programming languages.

The last part is the Parser. The parser is what's inside the foreach statement. This is recognizing the tokens 'a' and is going through all of them and thinking this: if the token starts with "print " then I will print everything after the 6th character in the string.

There are more parts to a programming language but this, but this is just a basic programming language and more parts aren't needed.

I hope that everyone that reads this learns something new from it and that you now realize that making a programming language isn't as hard as you think.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900