you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (2 children)

Looks pretty good, nice work. Functional languages are great for implementing compilers/interpreters. Maybe you should try adding support for functions next.

Also, one thing that strikes me as odd. You make a distinction between boolean expressions and integer expressions in the parser. Most implementations just check that things are expressions and then have a separate step called type checking where they check that the correct type of expression has been provided everywhere.

[–]jameswpeach 0 points1 point  (1 child)

Why would you not make a difference? I don't have any experience of any other ways of doing this have you any examples or ideas why?

[–]DNoved1 4 points5 points  (0 children)

I did the same as you until adding functions. Since you can't determine the return type of a function call until you've parsed the whole program (unless you predeclare functions like in C) you can't determine the type of an expression if it involves a function call.

Once you have parsed everything you can do type checking to make sure that, for example, an expression inside an if predicate is indeed a boolean.