Creating my own programming language

Pages: 12
How would I go about creating a programming language? Like, creating a compiler for it and what not. I don't know where to start with it. I know it's going to take A LOT of time, but I'd like to get an idea of how to do it. Like some open source examples or whatever.
First you need to define its purpose, syntax (in form of a formal grammar) and semantics (what is the meaning/behaviour of all the valid constructs in your language). Then you can start coding it ;)
Alright.. I'll plan out something tomorrow, it's like 4:16 AM here. Then I'll post something I guess. I remember talking to Albatross before and she was writing her own language but I haven't talked to her in a long time. Maybe she could help me. She's on this forum somewhere.xD
Most if not all programming languages have a grammar. So to create a new programming language start off with a grammar. I believe there are tools to do that.
I think a big question to ask is: Are you looking for a compiled language or an interpreted one?
One good way of creating a programming language is to make it interpretable, meaning that even though it is your own programming language, it uses other programming language to compile your code(s), if not even run your program. Python & Ruby are one of those kind of programming languages.

If you plan to do it this way, I´d recommend using C, because it is low-level & portable, but I guess C++ would do the trick, too.

Note that interpreted programming languages might be bit slow, but perhaps you should do it this way first & see how it turns out. Creating your programming language isn´t easy, so start small.

Wish you the best. Good luck!
C++ is also low-level and portable...
I realize how difficult creating a FULL compiler will be extremely difficult. I think' i'll just start with an interpreter.
The difference between a compiler and an interpreter is supprisingly small.
closed account (zb0S216C)
If you're planning on designing a fully-fledged programming language, you're going to have to ask yourself some questions, such as these:


1) Why am I making an entirely new language?
2) What will make my language stand out?
3) What will my language offer that others don't?
4) What tools will I use?
5) What features does it have?
6) Is it an object-orientated language?
7) What level is it?
8) Who's my target audience?
9) Have I got the time and patience for such a project?
10) What's the structure going to look like?
11) Am I going to be a Billy on this project?

There're considerably more questions and factors to take into consideration.

Wazzak
1) To learn.
2) Nothing.
3) Nothing.
4) C++.
5) All the basic stuff structured programming stuff + file I/O.
6) Of course not.
7) Beginner.
8) Me.
9) Possibly not.
10) IDK yet. TBD.
11) Just a Bob.

;-)
closed account (zb0S216C)
Duoas, thats hardly a satisfying language which even the most dullest of people won't use :)

Wazzak
Duoas, that's about right :P I don't want to create another C++ just something I can make to learn and what not. I'd just use it for creating simple apps or whatever. Nothing serious.
Framework, you are missing the point. No one can go out and just create the next big language from nothing. If you want to learn something new, even the simplest language is worth it. I derove a great deal of satisfaction from something my university professor called "L" which couldn't do much more than print "hello, world".

Here's a couple of my old "L" programs that I was pleased with:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* fibonacci.L

   Generate fibonacci numbers.
   Michael Thomas Greer
   5 April 2005

   Example usage:
     li fibonacci 45
*/

// Get the index to compute.
if length args == 0
  then // (From user)
    write "Calculate fibonacci of what n?> ";
    readln index
  else // (From command-line)
    index := args::0
  end;

index := int index;

// Compute fibonacci( index )
prev := 0;
curr := 1;
cntr := 0;

while cntr < index do
  next := prev + curr;
  prev := curr;
  curr := next;
  cntr := cntr +1
  end;

result := curr;

writeln ("fibonacci of " + (string index) + " is " + (string result))

// end fibonacci.L 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* lcm.L

   Calculate the Least Common Multiple of N numbers
   Michael Thomas Greer
   5 April 2005

   Example usage:
     li lcm 12 13 14

   --> result = 1092

*/

if length args < 2
  then writeln "You must specify at least two numbers, eg:\n"
             + "  li lcm 3 4\n"
             + "  li lcm 3 4 5"
  else

a    := int (args::0);               // a <-- first number in list
argi := 1;                           // index of next number in list

while argi < length args do
  b    := int (args::argi);          // b <-- next number in list
  argi := argi +1;

  // Calculate the LCM of a and b
  ma := a;
  nb := b;

  while ma != nb do
    if ma < nb
      then ma := ma +a
      else nb := nb +b
      end
    end;

  a := ma                            // a <-- result of last LCM
  end;

result := a;

write   "result = ";
writeln  result

end // lcm.L 

I spent a lot of time on types and type conversion and operators. Looks awful, sure. Doesn't do much, sure. But I learned a lot -- enough to get me started on bigger and more complex things. And I had fun.

So what exactly do you want the OP to create?

Troy
Spend some time figuring out these things:
  ■ What kind of things do you want your language to do?
  ■ What do you want your language to look like? What kinds of rules should it follow?
  ■ What concepts are you familiar with?

That last one is important. How many languages are you familiar with? A good choice to begin writing your own language is to start with a stripped down version of BASIC or Tcl.

http://en.wikipedia.org/wiki/BASIC

http://wiki.tcl.tk/
http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm

Both of these are very simply designed, and can be implemented very naïvely with much variation and satisfaction.

Hope this helps.
Thanks, I'll look into it.
I think, the best way would be to make yourself familiar with compiler design, e.g. by reading the seminal book "Compilers: Principles, Techniques, and Tools (Aho,Sethi,Ulman)". You will learn about standard compiler tools like yacc/bison, lex and so on, and with these tools it is comparably easy to do that (the input is a grammar specification, the output C-Code that directly could be used).

To build an interpreter with these tools for an expert takes 3-5 days. The major effort is the grammar specification - i.e. to get an idea how the language should look like.
How would I go about creating a programming language?


I think that if the question has to be asked, the answer starts with "Practice programming for the next 5-10 years, then revisit whether or not you want to do it."

Of course. Asking the question means not being able to do it.
Personally, I´d love to create make a programming language in C++. It´s generic & object-oriented paradigms offer several benefits, in both design & maintaining. I have nothing against your programming language creation, because it definitely is ultimate challenge, yes, but also good practice.
Yeah, I decided to just to try creating an interpreter instead. So I like, open the code in my program and it runs whatever commands there are. This would be much easier in C# but I'm experimenting.
Pages: 12