Lambda programming language

From ArticleWorld


The Lambda Programming Language is a programming language based on lambda calculus and a simplistic von Neumann architecture with a linear memory space. The registers are also memory-mapped and allows for self-modifying code. It provides a small number of instructions

Lambda provides only one type (the integer), which also means that there is no way to actually write a "Hello, world" program (the compiler and the interpreter do not deal with ASCII characters).

The Lambda language

Lambda has a simple syntax with only four basic rules:

  • All instructions are separated by newlines; tokens are separated by spaces.
  • A ";" character at the end of an operator means that the operator is a GOTO label. The jump can be made by simply calling that operator
  • An instruction with an operator ending with a "!" character returns the address of the operator.
  • Comments can be written after "//" characters

Six basic instructions are provided (the number in parenthesis is the numerical opcode value of the instruction):

  • NOP (0): No operation, updates instruction pointer to next operation.
  • READ (1): Read a value from memory; it interprets the result of the next expression as a memory address, returning the value stored at it.
  • LOAD (2): Loads a value to memory; the expression immediately following is evaluated as the address, and the expression after it is evaluated to the value to be stored.
  • ADD (3): Adds a value to that of a memory address; the expression immediately following is evaluated as the memory address, and the one after it as the value to be added.
  • PRINT (4): Prints the value returned by evaluating the expression following immediately.

There are three memory-mapped registers:

  • The Instruction register, holding the address of the current instruction pointer. It is mapped at the address 32.
  • The Data register, holding the address of the next expression's start on jumps, enabling the machine to perform jumps. It is mapped at the address 34.
  • The Result register, holding the value of the current result while evaluating an expression. It is mapped at the address 36.

Examples

The following program prints the number 999 and demonstrates the usage of jumps:

print999
back:
exit
print999:
print 999
back
exit: