I have seen a lot of tutorials for making a programming language, but very few for writing one in Python. I would like to know how to (relatively easily) create a programming language using Python.
PLY stands for Python Lex Yacc. It is a library you can use to make your own programming language with python. Lex is a well known library for writing lexers. Yacc stands for "Yet Another Compiler Compiler" which means it compiles new languages, which are compilers themself.
Python is often compared to other interpreted languages such as Java, JavaScript, Perl, Tcl, or Smalltalk. Comparisons to C++, Common Lisp and Scheme can also be enlightening.
You can just take a subset of an existing language or come up with a simple variation of it and get started. However, if you have plans for creating your very own programming language, you will have to give it some thought. I think of designing a programming language as divided two phases: The big-picture phase.
Not sure what you mean by "creating a programming language". But I think you might like to read Peter Norvig's excellent article (How to Write a (Lisp) Interpreter (in Python)). This shows how you can build a Lisp interpreter in only 90 lines of Python!
Once you understood that, try (An ((Even Better) Lisp) Interpreter (in Python)).
Do these things carefully and deliberately, and after a few days of work you may have a halfway-decent parser for your language. Then you'll need to consume the output of the parser (if using ANTLR, consider using the Abstract Syntax Trees, or ASTs, that it can generate for you). Then you'll need to convert the parsed syntax into a target language, such as x86 assembly or some intermediate bytecode such as the one used by Java, Lua, Microsoft .NET, or whatever.
Good luck, and be forewarned: this process will take a long time to do right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With