No description
This repository has been archived on 2023-04-04. You can view files and clone it, but cannot push or open issues or pull requests.
Find a file
2022-10-16 20:14:55 +02:00
.github/workflows upload code 2022-10-16 20:14:55 +02:00
examples upload code 2022-10-16 20:14:55 +02:00
integration upload code 2022-10-16 20:14:55 +02:00
src upload code 2022-10-16 20:14:55 +02:00
stdlib upload code 2022-10-16 20:14:55 +02:00
templates upload code 2022-10-16 20:14:55 +02:00
.gitignore upload code 2022-10-16 20:14:55 +02:00
build.rs upload code 2022-10-16 20:14:55 +02:00
Cargo.lock upload code 2022-10-16 20:14:55 +02:00
Cargo.toml upload code 2022-10-16 20:14:55 +02:00
README.md upload code 2022-10-16 20:14:55 +02:00
rustfmt.toml upload code 2022-10-16 20:14:55 +02:00

Compiler

This is a compiler for a heap-manipulating symbolic probabilistic programming language that I'm designing as part of my bachelor thesis.

Types

  • bool boolean value
  • int integer value (either 32 or 64 bit, depending on the target architecture)
  • () empty tuple (also the default return value of functions, like void in C)
  • (..) tuple
  • Rc<_> reference-counting pointer
  • Option<_> optional value, can be None or Some(_)
  • $ident, $ident<..> custom type, must have previously been typedef'ed

Syntax

$program   => $typedefs $functions $inputs $main $outputs

$typedefs  => $typedef $typedefs
            | ε

$functions => $function $functions
            | ε

$inputs    => $input $inputs
            | ε

$main      => $stmt $block

$outputs   => $output $outputs
            | ε

$typedef   => type $ident = $type;
            | type $ident<$identlist> = $type;

$type      => bool
            | int
            | ()
            | ($typelist)
            | ($typelist,)
            | Rc<$type>
            | Option<$type>
            | $ident
            | $ident<$typelist>

$typelist  => $type | $type, $typelist

$function  => fn $ident($params) { $block }
            | fn $ident($params) -> $type { $block }
            | fn $ident<$identlist>($params) { $block }
            | fn $ident<$identlist>($params) -> $type { $block }

$params    => $paramlist | ε

$paramlist => $ident: $type, $paramlist
            | $ident: $type

$input     => input!($ident);

$output    => output!($identlist);

$stmt      => let $ident: $type = $expr;
            | $ident = $expr;
            | $ifstmt
            | { $block } [$float] { $block }
            | while $ifcond { $block }
            | { $block }
            | return;
            | return $expr;
            | continue;
            | break;

$block     => $stmt $block
            | ε

$ifstmt    => if $ifcond { $block }
            | if $ifcond { $block } else $ifstmt
            | if $ifcond { $block } else { $block }

$ifcond    => $expr
            | let Some($ident) = $expr

$expr      => $expr $op $expr
            | !$expr
            | -$expr
            | *$expr
            | ($exprs)
            | ($exprlist,)
            | $expr.$index
            | Rc($expr)
            | Some($expr)
            | None
            | $int
            | $bool
            | $ident($exprs)
            | $ident<$typelist>($exprs)

$exprs     => $exprlist | ε

$exprlist  => $expr, $exprlist
            | $expr

$op        => + | - | * | /
            | == | != | < | <= | > | >=
            | && | ||

$ident     matches all valid Rust identifiers
$identlist => $ident | $ident, $identlist

$bool      => true | false
$index     matches all non-negative integer values
$int       matches all integer values
$float     matches all floating-point values