Funclang is essentially a very small subset of OCaml. The language is purely functional, and all programs are one (large?) expression.
The language is currently a work in progress, but it has support for some basic features that you would expect from a functional programming language:
- Variable Assignments to int, bool, functions
- Functions, Recursive Functions
- Partial Application of Functions
- Lists (not typed (yet))
- Basic Pattern Matching
- Make sure you have Rust (and everything that comes with it) installed on your system.
- Clone this repository
- cd funclang_interpreter
cargo run
- Write your program
- cargo build
- cargo run -- path/to/program
This language is kinda just becoming a tiny subset of OCaml, so if you are familiar with ML style languages, the syntax should be very easy to pick up. There are a few example programs in the test_programs directory To run one: cargo run -- test_programs/peano_nums.fl
There are a few cool programs in the test_programs dir
To show AST:
-s or --show-tree
Runs program in file and prints AST:
cargo run -- test_programs/list_and_high_orders_out_of_functions.fl -s
REPL with AST printed:
cargo run -- -s
-
main.rs: entry point, either detects a file, runs interpreter and exits, or REPL
-
funclang.lalrpop: Defines the grammar for the programming language and creates parser that builds AST from source
-
ast.rs: Defines the Abstract Syntax Tree structure that the lalrpop parser will use to build the AST which will be evaluated by the interpreter. This file contains pretty printing helpers if you want to display the AST (All pretty printing code was written by an LLM)
-
value.rs: Defines the values (and errors) to which a program can evaluate (and to which variables can be assigned). This file also defines envs, which is the linked list structure used to keep track of scope and variable assignments from "let ... in ..." expressions.
-
interpreter.rs: The Tree-Walking Interpreter (and helper functions). eval function takes in an AST and env (for scope) and recurses over entire AST to produce a value