Question:
How do u create a programming language from scratch?
anonymous
2009-01-16 16:43:58 UTC
Hey i love computer codes... I have learned HTML, DHTML, C++, alittle bit Java, and other languages...

I want to create a program of my own and a complair as well...
u see when i was learning all these programs, at fist i had alot of trouble with c++, then i thought what if i make a language of my own it would be easier for me to make codes...

sSO...

Do any of u guys have any ideas how to do this impossible task...
Just give me some links.... I would appericate it...

I know alot of u guys have no clue, but plez try to help one lost guy who is trying to dive in to a bottemless, endless journey....
Three answers:
Shadow Wolf
2009-01-16 18:06:33 UTC
Rather than get you into learning a whole pile of things, I found a nice tutorial several years ago. This will get you started and allow you do do some simple things. This might actually help you decide if you need the power of some of the various compiler helper tools.



http://compilers.iecc.com/crenshaw/

This is a more or less complete tutorial on writing a simple compiler. You'll need to at least understand Pascal and assembly to get through it. With a bit of work you can make the tutorial output another language such as C rather than assembly.



Constructing Language Processors For Little Languages, Kaplan

Was an interesting book. It may be out of print now, but I found it useful. It fit into some programming I was doing at the time. Depending on what you do with programming, you'll find yourself doing little processors that read files and data in certain ways.



Writing Compilers and Interpreters, Mak

This book may get you where you want to go. My copy is 2nd edition and there may be a newer edition. Again, it has a lot of information in it.



My best suggestion is to google everything and do a lot of reading. You can go the YACC/FLEX route, but they won't give you anything close to a working compiler. There is a lot of other work involved. I suggest the books and the tutorial as they will get you doing some things. If you need more, then go to the compiler building tools.



Start simple and build on it like the Crenshaw tutorial. Write a simple GUI interpreter to help you develop your programming language.



The highly popular C programming language didn't start as C in it's current form. There are earlier versions that started with A, then B, then K&R C, and in more recent years, the ANSI C that most are using today. Even the ANSI standard C has undergone some changes. Finally, C++ was designed as an object oriented version of C that was compatible with C. Microsoft was unhappy with how C++ worked so they changed some things and we have C# now.



What ever route you decide to go, you will learn a great deal more about things you probably didn't even know existed.



Shadow Wolf
videobobkart
2009-01-16 16:57:27 UTC
I've done this numerous times, both at the hobby level and professionally, both special-purpose and general-purpose languages.



You need to know about lexicon, syntax, regular expressions, context-free grammars, abstract syntax trees, static semantic analysis, code generation and optimization techniques, just to name a few. There isn't room here to go into all that you will need to know for this (nor do I have that kind of time), but the numerous links below should scrape the surface.
SĂ­dhe
2009-01-16 17:11:23 UTC
Most languages start as a form of another language. For example, Java is considered C-like, HTML inherits from SGML, and so forth. So, first you want to explore what the basic form of your language is.



Once you have determined the basic form, you need to codify its grammar. The standard way of doing this is to document it in Backus-Naur form (or simply BNF). BNF is a language that describes grammars and the "official definition" of a programming language is nearly always described in BNF.



http://en.wikipedia.org/wiki/Backus-Naur_form



Once you have your language defined in BNF, you need to create a parser for your language.



What's nice about having BNF is that there are tools to generate a parser for you from your BNF. One such example of this, used for compiled programming languages like C, is a program called YACC (Yet Another Compiler Compiler)



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

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



Once your parser is complete, you need to turn the source code of your language into "tokens" for your parser to chew on. This is where a lexical analyzer comes into play.



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



Just like YACC, there's a number of tools available to assist with building these. The classic tool for this is called "lex", but there's more current variants such as Flex.



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



Granted, what you do with the output of these programs depends on what kind of language you are writing. You'd handle the output for an interpreted language much differently than a compiled language.



If your language is going to be compiled you'll need to write an assembler and linker for these outputs.



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

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



If your language is going to be interpreted, you'll need to write an interpretive runtime.



http://en.wikipedia.org/wiki/Interpreter_(computing)


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