Skip to content

small tree-walk interpreter and transpiler in c for a toy language

License

Notifications You must be signed in to change notification settings

rmrt1n/seacucumber

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Seacucumber

Seacucumber is a small, interpreted functional programming language written in C. It was inspired by other languages such as scheme, elixir, and OCaml. This project was done as an attempt by me to learn about programming language implementation and compiler theory.

Screeenshot of the language & interpreter

Built with

C

Build Instructions

Instructions to build Seacucumber from source. To actually use the transpiler, you will need to have OCaml installed on your system.

# clone this repository
git clone https://github.com/rmrt1n/seacucumber.git

# cd into the repository
cd seacucumber

# build seacucumber
make

Usage

scc is the executable for the tree walking interpreter, while tscc is the Seacucumber-to-OCaml transpiler. Below are the commmands to run the programs. For examples of programs written in Seacucumber, checkout the examples directory.

# run an interactive prompt
./scc

# interpret seacucumber code 
./scc FILENAME

# tscc will compile seacucumber to ocaml,
# and run ocamlc to create an executable
./tscc FILENAME

Language Grammar

Here is the BNF grammar of Seacucumber:

program -> form* EOF

form -> (expression | assignment)

assignment -> "let" IDENT "=" expression

expression -> "if" logic_or "then" expression (else expression)?
            | "fn" "(" params? ")" "->" expression
            | block
            | logic_or

params -> IDENT ("," IDENT)*

block -> "do" form* "done" ";"

logic_or -> logic_and ("or" logic_and)*

logic_and -> equality ("and" equality)*

equality -> comparison (("==" | "!=") comparison)*

comparison -> addition (("<" | ">" | "<=" | ">=") addition)*

addition -> multiplication (("+" | "-") multiplication)*

multiplication -> unary (("*" | "/") unary)*

unary -> ("!" | "-") unary | call

call -> primary ("(" args? ")")*

args -> expression ("," expression)*

primary -> NUMBER | STRING | IDENT
         | "true" | "false" | "nil"
         | "(" expression ")"

License

Distributed under the MIT License. See LICENSE for more information.