At some point in time I got interested in compilers and interpreters and all those weird things, and I came across this wonderful blog post. I immediately started following the "Let's Build a Simple Interpreter" series to write my own Pascal interpreter with Python, which is the aim of that series.
At that time there were only 5 or 6 posts, and I got to the point where I had done everything he told us to do and couldn't wait for the other posts, as I noticed the frequency with which the author posted in that series was rather low. At that point, my project's aim diverged of that of the blog and I tried using what I had learned to create a very basic programming language I called Roj.
The end product of that is a programming language with some common constructs, such as the while loop and the if-else. The code and some snippets written in Roj can be downloaded from here. In there you can also find my attempt at formalising Roj's grammar with Backus-Naur Form.
To run one of the snippets, run the RojInterpreter.py file, which starts a REPL. You can type Roj programs in one line or you can type execute filename where filename is the path to the file you want to execute:
Please bear in mind that the REPL does not save variables and whatnot from the previous lines. If you want to type a Roj program directly into the REPL, it will have to be a one-liner.
[Pt] A minha curiosidade vagueia incessantemente, e houve um dia que se fixou nesta publicação sobre compiladores. Comecei a seguir essa série, mas rapidamente cheguei ao ponto em que já tinha de aguardar pelos posts que se seguiriam. Por causa disso, desviei-me um pouco do objetivo final da série e criei uma mini linguagem de programação, a que chamei Roj. Nesta pasta vão encontrar o código fonte todo que faz com que as engrenagens do Roj funcionem, e na imagem em cima vêem um pouco do que se pode fazer com o Roj.
O ficheiro que interessa para porem coisas a correr, é o RojInterpreter.py. Basta correr esse ficheiro com o Python e entram num REPL como o que podem ver na imagem. Podem escrever programas numa linha, ou podem executar ficheiros que tenham programas. Aviso apenas que, de uma linha para a outra, as variáveis não são guardadas. Se quiserem escrever um programa diretamente no REPL, é preciso escrever o programa todo de seguida numa linha. Na pasta cujo link deixei, podem também encontrar uma tentativa de formalização da gramática da linguagem, usando BNF.
Let me know what you think!
-RGS
Creating a programming language from scratch!
Reviewed by Unknown
on
October 14, 2017
Rating:
![Creating a programming language from scratch!](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtZKv8kjmOSwS9nSMnRNgb6os9KmeLW6B84oVCcRdiR5CFa744GUxA9e6s35R4t17CaKjk3gCgTnw1_c77ef5vcBE1FGDdZLdk6S73rINlmbA_0ucwgGYqJhmxEqStIarxjCOvqvCopCY/s72-c/programming-original.jpeg)
No comments: