diff --git a/HOME_EXAM.md b/HOME_EXAM.md index de5a6e1204e4a57b127a7cf235ec98d139dea4b6..2487bb876897fd87fd3a57807f4dd987eccc89a2 100644 --- a/HOME_EXAM.md +++ b/HOME_EXAM.md @@ -198,6 +198,9 @@ Showcase of EBNF: let c = a / 3; if (c > 0) { true + } + else { + false } } @@ -374,7 +377,7 @@ let a = 2; ### Assign expression ```math -\frac{<e, σ> → n}{<mv = e,σ> → σ'[mv=n]} +\frac{<e, σ> → n}{<e, σ> → σ'[mv=n]} ``` Where the expression also can be a boolean or function. @@ -408,7 +411,7 @@ else { ``` ``` rust -let a = 0; +let mut a = 0; while a < 10 { // something that should loop 10 times a = a + 1; @@ -434,6 +437,9 @@ fn func(x:i32, y:i32) -> i32 { let c = a / 3; if (c > 0) { true + } + else { + false } } @@ -454,6 +460,7 @@ fn func(x:i32, y:i32) -> i32 { - →, evaluates - c, command - v, variable +- mv, mutable variable - e, expression - t, type @@ -518,7 +525,7 @@ false < 2; // Type missmatch ``` ```math -\frac{<e,σ> → \&text{mut } t}{<*e,σ> → \text{mut} t} +\frac{<e,σ> → \&\text{mut } t}{<*e,σ> → \text{mut} t} ``` ```math @@ -537,20 +544,23 @@ let d:bool = *b; // <-- Type missmatch \frac{<f(e), σ> → t}{<f, σ> → \text{ret } t} ``` +```math +\frac{<e_1, σ> → <t_1, σ^1> ... <e_n, σ^{n-1}> → <t_n, σ^n> <f_{call}, σ^n[p_1=t_1, ..., p_n=t_n]> → <t_{res}, σ'>}{<f(e_1, ..., e_n), σ> → <f_t, σ'>} +``` + ``` rust -fn func() -> i32 { - 1+3 +fn example1() -> i32 { + 1+3 // This is okay return type } -fn main() { - let a = func(); - let b:bool = a(); // Type missmatch +fn example2() -> i32 { + true // This is a type missmatch with what type is expected to return } ``` ### Let expression ```math -\frac{<e, σ> → t, σ'}{<v := e,σ> → σ'[v:=n]} +\frac{<e, σ> → t}{<{/text{let } v = e,σ> → <(), σ[v=t]>} ``` ``` rust let a:i32 = 1; @@ -598,13 +608,13 @@ else { ``` ``` rust -let a = 0; +let mut a = 0; while a < 10 { // something that should loop 10 times a = a + 1; } -let a = 0; +let mut a = 0; while a * 10 { // Type missmatch // something that should loop 10 times a = a + 1;