GitHunt
YO

Yowgf/Plc-language-interpreter

Interpreter for Plc - an ML-like functional language.

Plc language interpreter

Plc is a simple ML-like functional language, that supports basic arithmetic and list operations, recursion, and high order functions. Ultimately, every expression is evaluated to a value of the type internally called PlcVal, that can be either: an integer, a boolean, a list, a sequence, or a closure.

Try it out

Plc is built on top of SML. To run its interpreter, you need to have an SML interpreter installed in your machine. Once that is done, just run the bat or shell script "plc" (make sure that either you are in the root directory of the project or that you have it in your PATH), as in:

$ plc

or provide a script to be executed:

$ plc my-script.plc

Examples

Calculate the factorial of 10 recursively. Note that there must be an expression following the ";". Different from SML, a function declaration by itself is not a valid program.

fun rec fat (Int n): Int = 
    if n = 0 then
        1
    else
        n * fat(n-1);
        
fat(10)

Calculate the 8th fibonacci number.

fun rec fib (Int n): Int = 
    if n = 0 then
        1
    else if n = 1 then
        1
    else
        fib(n - 1) + fib(n - 2);

fib(8)

Languages

Standard ML86.1%Yacc8.5%Lex4.7%Shell0.4%Batchfile0.3%

Contributors

Created February 25, 2021
Updated November 19, 2023
Yowgf/Plc-language-interpreter | GitHunt