Skip to content

0918nobita/psyche

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
bin
 
 
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Psyche

OPAM

A WASM friendly lightweight programming language implemented in OCaml

Usage

psyche <command> [<args>]

Commands:

  • make : Compile a source file specified by the command line argument.

make sub command

example.psy :

pub fn main() {
  fib(7)  (* => 13 *)
}

fn fib(n) {
  if n == 0 || n == 1
    then n
    else fib(n - 1) + fib(n - 2)
}

Compile command :

psyche make example.psy  # produces out.wasm

In order to install or to build the Psyche compiler, ensure that you have OPAM installed.

Installing

opam install psyche

EBNF

comment = "(*", <STRING?>, "*)"

non_zero_digit = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

zero = "0"

digit = zero | non_zero_digit

integer = ["+" | "-"], (zero | (non_zero_digit, { digit }))

letter = "a" | "b" | "c" | ... | "z" | "A" | "B" | "C" | ... | "Z"

identifier = letter, { letter | digit }

if_expr = "if", logical_expr_or, "then", logical_expr_or, "else", logical_expr_or

let_expr = "let", identifier, "=", logical_expr_or, "in", logical_expr_or

funcall = identifier, "(", [ logical_expr_or, { ",", logical_expr_or } ], ")"

list_literal = "[", [ logical_expr_or, { ";", logical_expr_or } ], "]"

factor1 = integer | funcall | list_literal | ("(", logical_expr_or, ")") | if_expr | let_expr | identifier

factor2 = factor1, [ ".", "(", logical_expr_or, ")" ]

term = factor2, { ("*" | "/"), factor2 }

arithmetic_expr = term, { ("+" | "-"), term }

comparison_expr = arithmetic_expr, { ("==" | "!=" | "<" | "<=" | "=>" | ">"), arithmetic_expr }

logical_expr_and = comparison_expr, { "&&", comparison_expr }

logical_expr_or = logical_expr_and, { "||", logical_expr_and }

func_def = ["pub"], "fn", identifier, "(", [ identifier, { ",", identifier } ], ")", "{", logical_expr_or, "}"

program = { func_def }

Reference

License

This software is released under the MIT License, see LICENSE.

About

A WASM friendly lightweight programming language implemented in OCaml

Resources

License

Stars

Watchers

Forks

Sponsor this project