Last active
May 7, 2019 14:00
-
-
Save 0x00b1/7e647d83def008ba5c3cd58f61a4aa29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
record Node[T]: | |
a: Node[T] | |
b: Node[T] | |
data: T | |
type Tree[T] ← [Node[T]] | |
subroutine visit(item: Node[T], f: function (T)): | |
f(item.data) | |
items.visit(item.a, f) | |
items.visit(item.b, f) | |
example: Tree[unsigned 8-bit Integer] ← [1, 2, 3, 4, 5] | |
subroutine sort(items: [Type]) → [Type]: | |
increment ← ⌊count(items) ÷ 2⌋ | |
while increment: | |
for index, item in enumerate(items): | |
while index ≥ increment and items[index − increment] > item: | |
items[index] ← items[index − increment] | |
index ← index − increment | |
items[index] ← item | |
if increment = 2: | |
increment ← 1 | |
else: | |
increment ← increment × 5.0 ÷ 11 | |
return items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
⟨arguments⟩ ::= [⟨expression⟩ {“,” ⟨expression⟩}] | |
; | |
⟨block⟩ ::= “{” {⟨statement⟩} “}” | |
; | |
⟨conditions⟩ ::= ⟨condition⟩ {“,” ⟨condition⟩} | |
; | |
⟨condition⟩ ::= ⟨expression⟩ | |
| “case” ⟨pattern⟩ “←” ⟨expression⟩ | |
; | |
⟨expression⟩ ::= ⟨prefix⟩ [⟨infix⟩ {⟨infix⟩}] | |
; | |
⟨field⟩ ::= ⟨identifier⟩ ⟨type-annotation⟩ | |
; | |
⟨if-statement⟩ ::= “if” ⟨conditions⟩ ⟨block⟩ {“else” ⟨if-statement⟩} [“else” ⟨block⟩] | |
; | |
⟨infix⟩ ::= [⟨operator⟩] ⟨prefix⟩ | |
| “←” ⟨prefix⟩ | |
| (“as” | “is”) ⟨type⟩ | |
; | |
⟨postfix⟩ ::= (“true” | “false”) | |
| [“−”] ⟨floating-point⟩ | |
| [“−”] ⟨integer⟩ | |
| “(” ⟨expression⟩ “)” | |
| “[” ⟨arguments⟩ “]” | |
| ⟨identifier⟩ | |
| ⟨postfix⟩ “(” ⟨arguments⟩ “)” | |
| ⟨postfix⟩ “.” ⟨identifier⟩ | |
| ⟨postfix⟩ “[” ⟨arguments⟩ “]” | |
| ⟨postfix⟩ ⟨operator⟩ | |
; | |
⟨parameter⟩ ::= ⟨identifier⟩ [⟨type-annotation⟩] [“←” ⟨expression⟩] | |
; | |
⟨pattern⟩ ::= (“is” ⟨type⟩ | ⟨pattern⟩ “as” ⟨type⟩) | |
| “(” ⟨pattern⟩ “)” | |
| “[” ⟨pattern⟩ {“,” ⟨pattern⟩} “]” | |
| “_” | |
| ⟨expression⟩ | |
| ⟨identifier⟩ | |
| ⟨identifier⟩ “{” ⟨identifier⟩ “:” ⟨pattern⟩ {“,” ⟨identifier⟩ “:” ⟨pattern⟩} [“,” “…”] “}” | |
; | |
⟨prefix⟩ ::= [⟨operator⟩] ⟨postfix⟩ | |
; | |
⟨statement⟩ ::= “break” [⟨identifier⟩] | |
| “continue” [⟨identifier⟩] | |
| “for” ⟨pattern⟩ “in” ⟨expression⟩ ⟨block⟩ | |
| “goto” ⟨identifier⟩ | |
| “record” ⟨identifier⟩ “{” [⟨field⟩ {“,” ⟨field⟩}] “}” | |
| “return” [⟨expression⟩] | |
| “subroutine” ⟨identifier⟩ ⟨type-signature⟩ ⟨block⟩ | |
| “type” ⟨identifier⟩ “←” ⟨type⟩ | |
| “while” ⟨conditions⟩ ⟨block⟩ | |
| ⟨expression⟩ | |
| ⟨identifier⟩ “:” ⟨statement⟩ | |
| ⟨if-statement⟩ | |
; | |
⟨type⟩ ::= (“32-bit” | “64-bit” | “128-bit”) “Floating-point” | |
| [“unsigned”] (“8-bit” | “16-bit” | “32-bit” | “64-bit” | “128-bit”) “Integer” | |
| “[” ⟨digits⟩ “×” {⟨digits⟩ “×”} ⟨type⟩ “]” | |
| “Boolean” | |
| “function” ⟨type-signature⟩ | |
| “pointer” ⟨type⟩ | |
| “⊥” | |
| ⟨identifier⟩ | |
; | |
⟨type-annotation⟩ ::= “:” ⟨type⟩ | |
; | |
⟨type-signature⟩ ::= [“(” ⟨parameter⟩ {“,” ⟨parameter⟩} [“,” “…”] “)”] [“→” ⟨type⟩] | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment