Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a language interpreter

I am trying to understand how a language interpreter works. Can you guys point me the general lines on how an interpreter works?

I mean, suppose I have some lines written like this

10  x = 200;
20  for r = x to 1000 step 1
25  z = r + 32;
30  print z;
40  next r;
50  end;

what's the best way to build an interpreter that could run something like that?

Having a large matrix containing all functions allowed and searching for a match? The first line, for example: it is assigning 200 to a variable x, but these are symbols that does not exist.

If you guys can give me the direction...

Thanks for any help.

like image 307
Duck Avatar asked Feb 28 '23 10:02

Duck


1 Answers

Compiler creation is a complex topic (an interpreter can be seen as a special compiler).

You have to first parse it - try to understand the syntax and then create some internal representation (abstract syntax tree) and then create some execution logic.

Wikpedia suggests http://mcs.une.edu.au/~comp319/

like image 79
johannes Avatar answered Apr 10 '23 22:04

johannes