Programming Languages

Started by
4 comments, last by agari 22 years, 10 months ago
How do people make programming languages? How was Java made... or C made or u know like that...
A great writer has said, "It is not how good the writer is which affects the reader, but the thesis of the story."
Advertisement
there used to be a site called the programmers vault, where there was a tutorial about this. I don''t remember any of the details, but basically you create a compiler using asm or whatever to compile your language. It''s not that easy, but that''s generally what they were promoting.

HHSDrum@yahoo.com
Polarisoft Home Page
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
You dont need to know asm, you just need to have access to an existing programming language. Very early software was written by explicitly typing in opcodes - very unreadable and difficult to code, but it didnt need a compiler.

To create a language you need to define a formal grammar - this is a set of rules which determine the syntax of the language. Once you have done this, you can implement the language.

The easiest thing to do is write an interpreter. This is a program written in an existing language that takes a file written in your own language, reads it according to the syntax rules defined by the grammar, and performs the appropriate action. This is how the original BASIC languages worked.

A better solution is a compiler. This is similar to an interpreter, but instead of running the program, it simply outputs the machine language opcodes to a different file. This file can then be run directly as an executable - much faster than interpreters because the overhead of the interpreter executable has been removed. This is essentially what C/C++ compilers do.
well, technically a scripting language is a language, but you still need something to interpret it.

HHSDrum@yahoo.com
Polarisoft Home Page
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Like Sandman said, to create a language, you need to define it''s syntax.

But to define, it''s syntax, you need to define what it is going to be used for.

For example, You could create a language that gives all the feature to make internet app. So reading file from different protocol would be included. It would also be able to easely create web page using this language.


Anyway, this first part is actually the most complex. The compiler and interpret are not trivial task, but are not more difficult than writing any other kind of software.


Now, how do you create the first compiler of the language. Well today you can use any other language you want like Java, C, C++, are some scripts language that are better at parsing text like Perl, Python.

There are also tools to help you write compilers. The most known are lex and yacc. They are use to help parse and check the syntax of you language with you having to write minimal code.



Did you know that most C compilers are written in C?!! what, how did that happen!!

It is done through a method call bootstraping(not sure about the syntax). Essentially what you do, is that you use another language to make a small but usefull subset of your language compile to machine code( say you use assembler). You now have a compiler. So now, you use the small usefull subset of your language to write a compiler for it!! You compile this compiler with your original asm compiler.

Well this gives you a compiler written in your language for your language. You can now drop the asm compiler and live happily.

You can then extend this new compiler by adding the parsing of the other feature of your languages.

Actually, today. nobody need go to the trouble of writing the first part of a C compiler in assembly. Just take any C compiler out there and use it to write a better C compiler.

A slightly easier way to prototype a new language is to write a compiler which compiles your new language into C, if your new language is conducive to such a thing. Some languages aren''t that conducive to such a practice, such as Prolog, which depends on a WAM (Warren Abstract Machine). But if your new language can be compiled into C, then you compile the C code, you then have an executable.

_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.

This topic is closed to new replies.

Advertisement