Skip to main content
GameDev.net gamedev.net
🔒 Locked

Writing your own programming language...

Started by Stashi Jun 22, 2001 at 9:25 PM 12 replies 1.2k views
Original Post
Stashi
Stashi
In what language...would you go about writing your own programming language..? Can you guys give me a brief-moderate synopsis of what goes into this? I mean, for starters, how would you get your language to be runable on OS''s like Windows, etc..? In what language would you program the language in? Assembly? Or what? Wouldn''t it be best to make a programming language in the lowest-level language for starters....because if you created a language through C, it''d be an even higher-level language then C itself...thus making it slow. So is assembly the best choice?
Martee
Martee
You need to differentiate between designing a language and implementing a language. Designing a language involves creating all the rules of syntax and semantics. Implementing a language would be writing a compiler for it. Since you''re talking about programming stuff, I''ll assume you mean implementation.

You probably wouldn''t want to write your compiler in assembly language. Writing a compiler for your language in ASM wouldn''t mean anything in terms of performance for the resulting executables that it produced. You would be much better off with a high level language such as C++, where you can use stuff like advanced string manipulation and expression trees with much less difficulty.

~~~~~~~~~~
Martee
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Stashi
Stashi
If thats the case, to use C++/C to write a language, then what is the point? Why not just use the C to begin with?

The only thing you would be changing is syntax! Like, if the command says "make a integer" then have it translate to "int a;". So is that all languages are? The same power, just different syntax?
Null and Void
Null and Void
It all ends up as binary in the end. If I were insane I could write a C++ compiler in VB. It would suck to do, but it''d be the same as every other C++ compiler out there (probably slower to compile though, and the speed of the executable depends on how much you optimize the ASM you''re compiler produces).

[Resist Windows XP''s Invasive Production Activation Technology!]
bishop_pass
bishop_pass
Ok, look. If you want to design a new language, the first thing you need to determine is the PURPOSE of the language. More on this later. Given a PURPOSE, you''ll probably find that it has a certain type of data structure relevant to its paradigm. If your new language truly has a procedural paradigm, then you would most likely build a protoype compiler which compiles your language into C. This makes it somwhat platform independent. If you actually achieve success in this regard, you can then look at the possibility of writing a compiler which compiles it into assembly language. This compiler would likely be written in C or C++, and it might in fact be partly written using Lex and Yacc.

Now, let''s look at some of these points I just raised. There had better be a purpose to your language that goes beyond changing the syntax of some language like C or Basic or Pascal. We don''t need another language that does the same thing but with different syntax.

Consider the following languages: C, C++, Lisp, Java, and Prolog. Each one of these languages has a different paradigm or at least a different purpose. You must understand the subtle differences here. C is a high level abstraction of assembly programming. C++ is extends C to an object oriented paradigm. Lisp uses a list data structure which is exactly the structure of a Lisp program statement, giving Lisp the ability to dynamically construct and evaluate its own program. Java employs a runtime environment which is platform independent, enabling instantaneous execution over networks. And Prolog is declaritive programming, generally running as a Warren Abstract Machine, or WAM.

Define a paradigm and purpose for your language. It should create its own niche. If the language is procedural, use a conventional language to write a compiler which will compile it into C. If the language emplys a slightly different paradigm, such as Lisp or Prolog, then you must build a system that operates on your language''s data structures and in an efficient manner. Very likely such a languge would have some type of on the fly interpreter.

I hope I have been informative. Good luck.

_______________________________
"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
Stashi
Stashi
Thanks bishop! Thats alot more informative then a google link
cMADsc
cMADsc
This past spring I took this class called Programming Language. In building a language you should consider some things:

Programming Domains
scientific appz, business appz, AI, system programming, scripting language, special purpose language




Language Criteria
readability, writeability, reliability, cost.....portability,



Langeuage Catergories
imperative, functional, logic, OO



Who says college is not useful?!!!!



-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."
Michael Tanczos
Michael Tanczos
Did you check out that Google link at all? It was probably one of the most informative answers to your question a person could possibly give.

In fact, that link even has articles that explain to you how to build your own compiler. There is indeed a lot to it.. as far as writing the compiler itself, you would use a language like C++ for it's string parsing abilities, as mentioned earlier. Why? Because your compiler will take the source code, analyze it's syntax, check it's grammar, check it's semantics, generate code, and possibly even optimize that code. Only after that is done, will it output binary code that is actually executable by the operating system. And for executable file format specs, I'd try a site like wotsit.org, which is hosted here at Gamedev.net.

Writing a compiler is not easy by any stretch of the imagination. There are entire college courses on the topic, but most of the research in the field remains in the code optimization end of the spectrum. (As lexical analyzers like Lex/Flex or CFG parsers like Yakk/Bison have already taken out most of the parsing work)

But again, I'm wondering why you would want to write your own language in the first place. I personally could see it's benefits if it was an interpreted language that you would embed into your programs. (if you didn't want to use an existing embedded language) Flipcode.com has a tutorial that is very helpful in implementing your own scripting language that uses Flex/Bison I believe.

---
Michael Tanczos


(no sig yet)
Fremmed
Fremmed
quote:
Original post by Stashi
In what language...would you go about writing your own programming language..?



I would write it in it''s own language.

quote:

Can you guys give me a brief-moderate synopsis of what goes into this?


nope. this topic is _far_ too comprehensive. a couple of semesters at a good college or university should get you started, though.

quote:

I mean, for starters, how would you get your language to be runable on OS''s like Windows, etc..? In what language would you program the language in? Assembly? Or what? Wouldn''t it be best to make a programming language in the lowest-level language for starters....because if you created a language through C, it''d be an even higher-level language then C itself...thus making it slow.



no. first of all you don''t "write a language". you''re thinking of writing an implementation of an already formalized language. to that I would have to say that a programming language with any respect for itself is self-hosted.

quote:

So is assembly the best choice?



assembly hasn''t been the best choice for a good couple of decades.

if you''re serious about this (and not just mistaken, as is my best guess (why on earth would you want to design a new programming language?)), I''d recommend "Structure and Interpretation of Computer Programs" by Abelson and Sussman for starters. Common Lisp; The Language 2nd ed. isn''t a bad read either.

but are you sure you''re not really talking about a scripting engine? I know there are noumerous tutoriols on that topic around.

hope none of this sounds patronising. it surely isn''t meant to.

--Gunnar
redigjohn
redigjohn
i''ve looked forever on tutorials on writing script engines they all go back to compiler design, flex and bison. A company has made a port of it for windows vc++ 6.0. so check that out i know there are numerous tutorials on the net about making interpreted languages like java, which is what you essentially want. Parses code lexxes code and you have your functions do the rest, possibly turn your tokens into assembly for compilation.
Beer Hunter
Beer Hunter
quote:
Original post by Fremmed
I would write it in it''s own language.



In that case, what language would you use to write the first version of the compiler? Obviously, the first version of the compiler cannot be written in its own language.

aegrimonia
aegrimonia
A Prime example of using one language to make another one would be a language i used to program in quite a bit. It''s called CLARION, (www.topspeed.com) it''s a database language that makes some of the most bullet-proof data handling code you could ever want. It was written in C i believe.

You can do things in clarion in minutes that it would take you hours or days to do with C++.

nes8bit
nes8bit
It''s true. Clarion is pretty easy to use and its quite fast from what my grandpa was telling me.

He used to work for IBM so don''t think he''s unexperienced because he''s old.

---------------------------------------------
My useless posts have been viewed gotta view images to view the couNter times
TIM: God@totalim.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.