Would writing an interpreter for a new language in an interpreted language like Python be a bad idea, in all aspects, for example speed.
Asked
Active
Viewed 47 times
1 Answers
1
Programming languages that are executed in runtime are normally slower than compiled languages but doesn't mean that it is bad idea to create you own interpreter.
You can write an interpreter language using python which the code can be compiled. The problem with this, is that your interpreter it could be probably slower than an interpreter that was wrote in C or ASM. Another factor that impact in the speed it is also the complexity of the language. It is not the same to compile a complex language like C++ than your own custom language that maybe can have a couple of reserved words and it is not object oriented.

Juan Lago
- 960
- 1
- 10
- 20
-
Beause I was thinking of writing the interpreter in Python and then letting it execute Python equivalent code when my code is interpreted. – Tristan Pops Kildaire Apr 11 '16 at 16:59
-
I first want to get the lexer done to tokenize all of the tokens into a list that can be read and executed upon. – Tristan Pops Kildaire Apr 11 '16 at 17:00
-
If you want to increase the execution speed you can develop a transpiler instead of an interpreter, so you language code can be translated directly to python or another language. – Juan Lago Apr 12 '16 at 10:52
-
I recommend you take a look to the Dragon book (http://www.informatik.uni-bremen.de/agbkb/lehre/ccfl/Material/ALSUdragonbook.pdf). It is one of the best books about compilers, and it is suitable for undergraduate level. Good luck with your project! – Juan Lago Apr 12 '16 at 10:59
-
Will check this out. Thanks. – Tristan Pops Kildaire Apr 13 '16 at 06:46
-
Does a lexer have to use regex or can it go through the input character by character (more tedious)? – Tristan Pops Kildaire Apr 13 '16 at 07:20
-
Use regex, because regex functions are pretty stable and work well. It requires time to understand how regular expressions work, but one of the things that differentiate a noob developer from a professional is the usage of regular expressions. Before to write your lexer, I recommend you towrite a highlighter for your language. You can write one for pygments (See: http://pygments.org/docs/lexerdevelopment/). – Juan Lago Apr 13 '16 at 07:41
-
Take a look to this as well: http://jayconrod.com/posts/37/a-simple-interpreter-from-scratch-in-python-part-1 – Juan Lago Apr 13 '16 at 07:43