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:
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:
<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.