Question:
How to create a new programming language?
San123
2012-11-02 22:02:43 UTC
Dear friends, i would like to create a new programming language. I would like to do this because, i have a passion for programming and creating new things out of it. I know languages like C, C++, Java and currently I'm learning Ruby. I am not sure where to start learning. Please tell me what are the tools are needed(lexical analyzer etc). I don't know what are the tools needed to develop new language. Please tell me the requirements from the scratch. Thank You
Eight answers:
Siju
2012-11-03 00:34:42 UTC
Hi,



Refer to the below link



http://www.codeproject.com/Articles/50377/Create-Your-Own-Programming-Language
Tarun Mohandas
2012-11-02 22:55:40 UTC
There are a lot of things brought to mind when you want to create a programming language. First of all please understand that it is not a one person job. The first an foremost thing you have to keep in mind when you want to create a PL is the structure of a compiler. That include concepts like

1. Lexical Analysis

2. Syntax Analysis

3. Semantic Analysis

4. Parsing

5. Intermediate Code generation

6. Code optimization

7. Actual code generation

8. Symbol table management

9. The grouping of phrases into passes

10. Compiler Construction tools

(these are various steps through which a compiler understands a code language)



Then you have to know all the algorithms of Greedy method, dynamic programming etc, that will help you in memory management and problem solving.



For code generation, you have to know assembly language, and intermediate code.



Start reading a textbook on Principles of programming languages and Compiler Designs and it will lead you to what you should do next.



All the best :) hope this helps :)
Jared
2012-11-02 22:28:47 UTC
First and foremost you MUST understand assembly. A programming language REALLY means writing a compiler--which means translating high level code (i.e. C/C++/Java/Ruby) to assembly instructions that can be run on the specified machine (and note that this assembly code has to be different for all of the different architectures--luckily, almost all ISAs are either x86 or x86-64--so writing assembly for those two is enough to get a large coverage). The HARDER part is that you ALSO need to write OS calls which is going to be different for Linux, Windows, and Mac (although Mac and Linux should be similar since they are BOTH unix based).





For parsing the language I would suggest learning lex and yacc (flex and bison are the free equivalents). A colleague of mine swears by Antler (which is a Java based parser) but I have never used it--you might want to look into it.





To develop a language you need 1) a lexer (this is easy) and 2) a parser (this is difficult). The lexer just breaks up the input file into tokens. The parser actually makes sense of the tokens. You need to be familiar with BNF to do this effectively. There are A LOT of complexities involved in correctly parsing a language (for instance you need to implement a lookup table for variables).



Here's an example. The following is valid C code.



{

int i;

for(i = 0; i < 10; ++i){

printf("hello");

}

}

{

int i;

for(i = 0; i < 10; ++i){

printf("goodbye");

}

}



But the following is NOT valid C code:



int i;



for(i = 0; i < 10; ++i){

printf("hello");

}



{

int i;

for(i = 0; i < 10; ++i){

printf("goodbye");

}

}





(this shows the need for a lookup table to determine scope of a variable). Then to make the programming language worth ANYTHING you have to employ ALL sorts of optimizations--which I am not going to go into (there are tons and most are NP-Complete and thus require complicated heuristics).



My advice to you, is that if this is what you want to do is to study Computer Science and focus on compilers. You might well be able to contribute to compiler technology if you are interested, but I somehow doubt you currently have the knowledge to make anything worthwhile.
anonymous
2012-11-09 23:45:06 UTC
All the language are good. But you are use C++ to create a new programming language.
amania_r
2012-11-04 12:00:22 UTC
You could do worse that starting with the unix tools yacc and lex



a lexical analyser and a compiler compiler
?
2016-10-08 06:58:25 UTC
All languages are ultimately device language--the langauge the chip is designed for. maximum chips have alot of similarity of their language like various of the 32-bit intel chips, although some have more advantageous sensible factors. Then, assembly language is used, because that device language is binary and not in any respect written by technique of hand. c or c++ then assemble assembly language code.
Blue (Abhi)
2012-11-04 10:07:13 UTC
You need to be expert in Compiler Design and Assembly Language..



But if you knew these,you would not ask this question
roger
2012-11-03 09:48:52 UTC
YACC is designed for that



http://dinosaur.compilertools.net/yacc/index.html



Yacc: Yet Another Compiler-Compiler


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