Simple Interpreter

Simple Interpreter

This was my A-Level Computing project from 2000/01 - an interpreter for a simple custom programming language - complete with Win32 GUI 🙂

The idea was to allow the user to step through a program and the interpreter would explain the execution steps as it progressed.

Custom Language

The language was fairly complete, and two examples are given below. Local variables need to be defined in the first block of the function - and square brackets were used for calls.

This first example calculates the sine of an angle using the Taylor expansion:

func null main[]
{
  var num angle = 45
}
{
  print["sin(", angle, ") = ", sine[(3.141592654 * angle / 180)], endl]
}

func num sine[var num angle]
{
  var num t_result = 0
  var num result = 0
  var num power = 1
  var num sign = 2
}
{    
  while (power <= 9)
  {
    t_result = ((-1 ^ sign) * ((angle ^ power) / factorial[power]))
    result = result + t_result
    power = power + 2
    sign = sign + 1
  }

  return result
}

This second example calculates a factorial - demonstrating recursion:

func null main[]
{
  var num value = 5
}
{
  print["factorial[", value, "]= ", factorial[value]]
}

func num factorial[var num value]
{

}
{
  if (value <= 1)
  {
    return value
  }
  else
  {
    return (value * factorial[(value - 1)])
  }
}

Code

The source code is available on my GitHub, although it is very old and messy!