PDA

View Full Version : how can i create my own programming language?


hus2005
12-02-2006, 05:16 PM
how can i create my own programming language?

overcontrast
12-02-2006, 06:36 PM
okay now pay attention here... first u sit infront of a conputer then type a lot of codes in assembly and drink a lot of coffee or beer (whatever u prefer). Dont sleep very often (this is a must). Keep doing the above for a couple of years and boom! u got urself a nifty programming language.

sorry if this dosent help

salmonmoose
12-02-2006, 08:10 PM
If you ever do a programming course at university you will likely have to write your own language at some point.

They do not have to be written in assembly. In fact, you could, if you were bored enough, write a c++ compiler in BASIC.

They can range in complexity from a line by line editor through to a fully fledged compiler.

Making a language that compiles code is somewhat more tricky than one that just interprets it;

It's a pretty general question however and fairly hard to answer with much detail.

MKR
12-02-2006, 08:35 PM
Take a class on it. Seriously, it's not a "How do I do x" kind of thing unless you want to use a premade one like LUA, and even then you need to understand how it works and know how to implement it.

playmesumch00ns
12-03-2006, 12:54 PM
I think a much better question is, "Why would you want to?"

pmsc.

Simon
12-03-2006, 03:52 PM
I think a much better question is, "Why would you want to?"

pmsc.

agreed. There are enough languages to do pretty much any computer based task needed.

The answer to your question really depends on what level of language you want or need. you could start in C and build a high level language, or at the other end of the scale start cutting out pieces of punchcard.

Tetsuyama
12-06-2006, 05:27 PM
I think a much better question is, "Why would you want to?"

pmsc.

Me three. Rather than ask how to write a computer language, it may be more useful to ask yourself, "What problem am I trying to solve?" Once you have the answer in hand, the next question to ask is, "Is there a language out there that is specifically geared to solving this problem?"

If you want to learn more about compilers and interpreters, probably the best known book is by Aho, Sethi, and Ullman: "Compilers: Principles, Techniques, and Tools". I'd also recommend reading about Niklaus Wirth - he developed a number of computer languages which were widely used for teaching purposes; his papers on the topic generally seem to receive favorable reviews.

If you want to have a language to integrate scripting in to your application, both Java and Python will do this fairly well. For Java, I think the article "Dirty Java" from Game Developer Magazine (July 1999) would probably be a good place to start. For Python, Penton's "Mud Game Programming" has an example of how to wind a Python interpreter in to your program.

salmonmoose
12-07-2006, 12:05 AM
Whilst there is actually no need for another programming language, building your own can be an interesting challenge, even if it's based of something else (there's a bunch of languages on wikipedia you could build yourself).

tibes
12-11-2006, 04:14 AM
Lex, Yacc and Bison can be used for this sort of thing - this site might be helpful - http://dinosaur.compilertools.net/

fred_lemaster
12-11-2006, 06:58 AM
Learning Scheme (http://schemers.org/) is also helpful for learning how to design a new language. Scheme's syntax is trivial and makes it easy to experiment with different semantic models without getting hung up on parsing.

Additionally there's a pretty informative post at Lambda-theUltimate about things to consider before designing a new language - http://lambda-the-ultimate.org/node/687#comment-18074 (Careful, these
are all computer scientists and the discussion can get fairly heady)

gga
12-11-2006, 11:20 PM
how can i create my own programming language?

Algorithm:

a) Make sure you are willing to spend anywhere from one month to thirty years on it. The more popular your language becomes, the more likely you will be forced to spend more time on it.

b) If this is your first language, don't keep reading. Just get onto a computer and start coding it in whatever way you see fit. Proceed to step c) only if you succeed in creating a language but you are unhappy with the performance, time it took you to create it, feature set or whatever. Your first language will (should?) probably be very simple and will suck... but if you finish it, you will have learnt how to do some stuff on your own and might have even created your own personal tricks in the process.
If you cannot create a language by yourself, chances are you will end up struggling creating a language that can compete in today's landscape. If that does not dishearten you, keep reading...

c) Okay... time to start again. If you are aiming at doing some specific task with your language, do some research. Find out what other languages allow you to do similar tasks and what their problems are (or, at the very least, what problems *YOU* perceive in them). If you are aiming for performance, find out what are the fastest languages within that domain (and ideally, why). The more you know about other languages, the less likely you will end up re-inventing the wheel. But, contradictory, the more you know about languages, the harder it can be for you to come up with an original idea that is not influenced by what you already know. So watch out for that...
As part of your research, you may be interested in reading books or papers about the subject. Someone already recommended the Dragon Book (Compilers: Principles, Techniques and Tools) which is a 20 year-old classic. Other good and more modern books include "Advanced Compiler Design and Implementation" by Muchnick, and "Engineering a Compiler" by Cooper.

d) Design the syntax of your language. For very simple languages, you can do this on your head, but for more complex languages, doing it on paper is a better alternative. There, you would specify what are its primitive types, syntax, grammar, etc. In some ways, if you end up writing your language's manual before the code, the better your chances will be of it being successful.

e) If you did d) properly, you have written a good specification which you will be able to show it to people that you trust and know about languages. They may then give you suggestions or offer you criticism BEFORE you write any code. Go back to d) based on their comments.

f) Translate the syntax into something that the computer can understand. Often times, you will use something like lex/yacc, or some more specific library like antlr, etc. The goal of this is to obtain at least an AST (abstract syntax tree), from the ASCII/Unicode files the user feeds to your language.
Note: you can skip step d) completely and just design the syntax of your language by doing f) directly. However, this may prove difficult later on to try to explain your language to others and it might make it harder for you to maintain your language without having inconsistencies or introducing backwards-compatability bugs.

g) Create functions corresponding to each task defined in the AST. As you create each function, you should also create a corresponding little program that acts as a test suite for the feature of your language (see: unit tests). This will help in catching bugs you may introduce later on when coding and will give you some degree of assurance in knowing your language is bug free.

h) Work on optimizing your AST and evaluation, usually with the goal of improving your language's performance. Depending on your language, some of the most common techniques that are hard to implement but give you the best results are JIT compilation and compiling to machine language. Simpler techniques include SIMD processing and byte-compilation. Other tricks that may yield some performance but only in specific cases include things like loop unrolling, tail recursion, single static assignment (SSA), advanced control-/data-flow techniques, instruction scheduling, register allocation, etc.
Also, since you are probably writing your code with someone else's compiler and language (say C and gcc), you must definitively familiarize yourself completely with its optimization settings.

i) Work on your language library. Most high-end languages these days also come with a lot of libraries to do specific tasks (access the web, work with databases, draw gui elements, etc).

j) Once you arrive at a decent prototype, try to convince other people to play with your language and provide you with feedback. Go back to c) to h) based on feedback provided.
If your language ends up being a failure, go back to a) and start it all over again.

fred_lemaster
12-12-2006, 05:21 AM
Also, since you are probably writing your code with someone else's compiler and language (say C and gcc), you must definitively familiarize yourself completely with its optimization settings.


Technically, if you write a general purpose language, all you have to do is write an interpreter for your language in another language, then you can write your compiler in the language you just designed. Then you compile your compiler with the interpreter to bootstrap your language.

gga
12-12-2006, 12:14 PM
Technically, if you write a general purpose language, all you have to do is write an interpreter for your language in another language, then you can write your compiler in the language you just designed. Then you compile your compiler with the interpreter to bootstrap your language.

Theoretically, yes. In practice, it does not happen very often.
Only if your goal is not to build a language for speed or you do succeed at basically replacing the original base language's performance. Currently, the only language I can think of that can truly say to have succeeded at doing so is C (vs. Assembler).
Most other languages (C++, Fortran, D, C#, Java, Python, Ruby, Perl, Lua, Lisp, etc) are still more successful in their C implementations, afaik, than in their native ones (if there are any).

darktding
12-12-2006, 04:45 PM
I think a much better question is, "Why would you want to?"

pmsc.

oh because u want to irritate those trying to sharpen their skills in languages out there? in my experience it was tcl when I was trying to wrap my head around creating those slim templates... its a small example as to why what may work for you, might possible be very difficult to adopt for the masses. C++ and Python are perhaps the best languages that have all that one needs anything else is just pure abuse and harrasement for those trying to get work done...

fred_lemaster
12-12-2006, 05:49 PM
Most other languages (C++, Fortran, D, C#, Java, Python, Ruby, Perl, Lua, Lisp, etc) are still more successful in their C implementations, afaik, than in their native ones (if there are any).

Actually Sun's Java compiler is written in Java. The most successful Lisp implementations are all written in Lisp. Python has at least one self hosting implementation (PyPy) . Back in the day, Fortran compilers were either written in Assembly or Fortran. Most of Wirth's languages (Pascal, etc al), bootstrapped themselves as well. I think the major advantage of a self hosting language is that if someone wants to add language features they don't need to learn anything but the target language.

CGTalk Moderation
12-12-2006, 05:49 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.