Skip to content

Commit

Permalink
Complete syntax reflecting the AST
Browse files Browse the repository at this point in the history
  • Loading branch information
denismerigoux authored and franziskuskiefer committed Mar 16, 2022
1 parent 30ebde2 commit 0e710b3
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/language/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,49 @@
```
P ::= [i]\* Program items
i ::= array!(t, μ, n) Array type declaration where n is a natural number
| nat_mod!(t, n) Modular integer
| fn f([d]+) -> μ b Function declaration
| type t = enum { [c(μ)]+ } Enum declaration (with constructors)
| type t = struct([μ]+) Struct declaration (without named fields)
| const x: μ = e Constant declaration
| use crate::* External crate import
d ::= x: τ Function argument
μ ::= unit|bool|int Base types
μ ::= unit|bool|u8|U8|i8|I8... Base types
| Seq<μ> Sequence
| String Strings
| ([μ]+) Tuple
| unit Unit type
| t Named type
τ ::= μ Plain type
| &μ Immutable reference
b ::= {[s;]+} Block
s ::= let x: τ = e Let binding
p ::= x Variable pattern
| ([p]+) Tuple pattern
| t (p) Struct constructor pattern
| _ Wildcard pattern
s ::= let p: τ = e Let binding
| let mut p: τ = e Mutable let binding
| x = e Variable reassignment
| x = e? Variable reassignment with error catching
| let p: τ = e? Let binding with error catching
| if e then b (else b) Conditional statements
| c(e) Enum injection
| match e { [c(p) => e]+ } Pattern matching
| for x in e..e b For loop (integers only)
| e Return expression
| b Statement block
e ::= ()|true|false Unit and boolean literals
| n Integer literal
| "..." String literal
| t([e]+) Array literal
| e as μ Integer casting
| x Variable
| () Unit
| f([a]+) Function call
| if e then e else e Conditional expression
| e ⊙ e Binary operations
| ⊘ e Unary operations
| ([e]+) Tuple constructor
| e.(n) Tuple field access where n is a natural number
| x[e] Array or sequence index
a ::= e Linear argument
| &e Call-site borrowing
Expand Down

0 comments on commit 0e710b3

Please sign in to comment.