Interpreter/Compiler

Interpreter/Compiler

Advertisemen

For a module next year I will have to write a compiler capable of division by zero. I thought I would get a headstart on this by coding a compiler now.

Though after coding a lexical analysis stage, I realised this is going to be insanely hard. So I thought I might as well so if I can interpret the code directly after the lexical analysis stage.

Currently you can't do much in the code, only set and print variables. No sums, no user input just those two things. And the variables are only integers.

Variable declaration
var a is 3248
This will set variable a to 3248

Comments
Lines of comments begin with an exclamation mark
!This line is a comment

Printing
var a is 3
out a
!this will print "3"

Variable reassignment
var a is 5
a is 6
out a
!outputs "6"

There is also error detection in the language, i.e. if you try to use a invalid variable or invalid commands.

The screenshot below shows the interpreter doing its work. The output at the top of the console is just details of the lexical analysis, the bottom of the console is the actual output from the code.

ps://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoBZjlug_zZqUwiTQMTUGWmUniTps6uDAjNz2x43YE2JwbubEVaD36iSSRF-b_TZrrmDJRsBpJp3pC6A__OAkwmQsvTh_4gCIwRb_41CNtpUCAeZFlTh_WFm3SCx6O79Ti06jNDNP4NA/s1600/interp.png" style="margin-left: 1em; margin-right: 1em;">

Since the code is very basic currently, the interpreter will also convert the input code to C++:


Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Game Engine Tutorial