How can I design a new programming language? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 15

How can I design a new programming language?

31st May 2017, 6:38 PM
Ranjan Bagri
Ranjan Bagri - avatar
3 Answers
+ 22
Take a pen and paper and write down a specification :P Knowing shortcomings of other languages helps so you can do it better in your language. If you want to program with it, you need to write some code that runs code in your language (like, all your PHP code is run by something written in C or C++). It's pretty hard stuff, but here's the most important steps, and a few keywords for you to look up: 1. (optional) write down an 'EBNF grammar' of your language 2. write a 'lexer' that 'parses' your code into 'tokens' 3. write a 'parser' that 'parses' your 'tokens' into an 'abstract syntax tree' 4a. write an 'interpreter' that runs your 'abstract syntax tree' 4b. write a 'compiler' that translates the 'abstract syntax tree' to another language (C, x86 assembly, llvm are common targets) Alternatively, there are tools called 'compiler compilers' and 'parser generators' (like yacc, peg.js, ...) that can help you with a big chunk of the work (but not all of it). Writing an interpreter for a 'stack-based' language is probably the most easy thing to do, so that's a place to start. As far as parsing goes, 'recursive descent' parsers are easy to write by hand. I suppose people have written tutorials about writing interpreters where they talk about all these things in more than a few sentences, so go ahead and look those up :)
31st May 2017, 7:43 PM
Schindlabua
Schindlabua - avatar
+ 10
thanks for information 👍
31st May 2017, 7:22 PM
Ranjan Bagri
Ranjan Bagri - avatar
- 7
The question is why would you want to reinvent the wheel. Instead rather look into designing a layer over a set code
1st Jun 2017, 7:10 PM
Wayne Erasmus
Wayne Erasmus - avatar