Question:
How do you create a programming language?
anonymous
2009-11-29 22:02:04 UTC
I'm bored, and have nothing of real interest to do, so i was wondering how to create a programming language. It has be be something that can be used without a compiler. Any help is apreciated.
Three answers:
coolanswerer
2009-11-30 18:12:32 UTC
It has to "something that can be used without a compiler"? Do you mean that you have no available software and are trying to create this with any programming language that requires you to install anything or that your finished language won't need to be compiled?



I can't help you in the former case, but in the latter I recommend the use of ANTLR (ANother Tool for Language Recognition). It works with many existing programming languages (Java, Python, C#, etc.) and with it, you can make your own language.



The ANTLR site itself has some pretty good tutorials, if you want to go in depth, buy or pirate a copy of the Definitive ANTLR Reference. It covers the basics even if you have no previous experience in implementing operating systems.
Lie Ryan
2009-11-29 22:24:00 UTC
A programming language is either compiled, interpreted, or compiled-then-interpreted.



A compiled language translates source code into machine code. You got to know assembly and low level stuffs to create compilers. Otherwise, you can piggyback on existing compiler (e.g. C compiler) and create a translator that translates your language to that middle language (e.g. translates your language to C).



An interpreted language is the simplest of all; you simply read the source file line by line and do actions based on it. Example: javascript



Compiled and interpreted requires you to write two programs: the compiler and the virtual machine. Examples of compiled-then-interpreted language is Python (CPython) and Java.



In all three, you will definitely need to write a parser. You can write your own parse, or use a parser module others have written. There are two main methodology of parsing: Top-Down parser and Bottom-Up parser. You'll need to do lots of string processing.



For writing compilers, you will need to parse these strings into a syntax tree. The syntax tree basically represent the basic elements in source code. This syntax tree is then converted to either a machine code or bytecode. For interpreted language you may not need to built a full syntax tree, but it is useful anyway.



Writing a programming language is a huge work, I haven't even mentioned about designing the language itself. If you're just bored, you probably won't be able to write a full-fledged compiler or virtual machine.



For some little project, it is possible to write small interpreter for a small esoteric language like Brainfuck: http://en.wikipedia.org/wiki/Brainfuck



If you're proficient with your language, it will keep you occupied for a few days or a few hours at least.
Ped
2009-11-29 22:21:10 UTC
Well a programming language is not something that generally comes out of a hobby. A programming language is basically a compiler.

If you dont wana use a compiler you better be writing in machine language or even lower, a microprogram!!!.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...