Skip to content

shnela/interpreter

Repository files navigation

This project contains bnfc generated files. This is the same grammar as in the first task (I've only changed comments pattern).

Solution is included in the following files:
Interpret.hs:
- which is responsible for reading input file
- I suggest you to use helper functions: shof_info and debug, wchich are uncommented in my code

Misc.hs:
- this file is responsible for state management
- stored in state:
  - [Vst] variables
  - [Fst] functions
  - [Bst] output buffer - PRINT function as well as error messages are printed at the end of the program
  - [Stc] stack (which helps to declare nested variables and recursion)

Interpreter.hs:
- main part of the interpeter code

Interpreter checks types dynamically during program run and applies default conversions if only it's possible.

Instruction for (FOR in IN exp ...) has protected counter (variable id is stored one state 'below' block state, so relevant changing its value is impossible, but value can be read in the same time. Expression exp is evaluated once - before first loop.

Variable declarations are limited to one per block, but in inside block you can declare new variable with the same name as in outisde block (similar to C++).

Function declarations are allowed only in the outer block (it's allowed by grammar, but not by implementation).

You can check interpreter by running on students machine (threre may be problems with ghc higher than version 7.6.3)
$ make
$ ./interpeter ./good/some_program.shl # for good examples
$ ./interpeter ./bad/some_program.shl # for examples which generate errors

About

Jakub Kuszneruk

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published