Skip to content

astro-gad/karm_parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

116 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Karm Language

A simple language inspired by StandardML. In my journey of understanding how compilers works, there is KARM. It's only a project but it's kind of like my baby. Just a little language, with a grammar and a syntax that I made myself.

StandardML Affirmation-based language

Summary

Contribute

Requirements

  • Running on linux (required by termion >= 3.0.0)
  • rustc >= 1.75.0
  • cargo >= 1.75.0

Git workflow

To submit your code, create a PR on the dev branch, which will be reviewed later on and merged on main if the feature is stable and legitimate.

Please document all your code, especially the structs fields and the functions by providing their specification. You can get inspirations from the actual code.

Technical specificities

Caution

This section, especially the grammar, is subject to changes. Here is the BNF of the language's grammar :

program = expr;

expr = let | app | if-expr | interrogative | '(' expr ')';

# Affirmative expr
let = 'let' affirmative 'in' expr;

affirmative = id '=' ( type | fun );

type = 'type' ( product | sum );

fun = [ 'ifx' ] 'fun' [{ id [ ',' id ] }] '->' expr;

app = id [ '(' { id ',' } ')' ];

if-expr = 'if' expr 'then' expr 'else' expr;

interrogative = '?' affirmative;

term = id | literal;

literal = numbers | strings | booleans | chars;

Examples

Hello World!

let main = print("Hello, World");

(The print function will be part of the standard library)

Fibonacci

Basic implementation of the fibonacci sequence in Karm :

let fib n = if n <= 1 then n else fib(n - 1) + fib(n - 2);

Usage for question exprs

(* Here it's annoying cause `x: Str` should be an affirmation but it has little sense to define something as let x: Str in if x is not defined. Or it could be empty instance. *)
let show x =
    if (? x: Str) then print(x)
    else if (? x: Int) then printf("{i}", x)
    else if (? x: Bool) then printf("{b}", x);

About

A parser / maybe compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages