Skip to content
Snippets Groups Projects
Commit d8385e3a authored by David Söderberg's avatar David Söderberg
Browse files

Update HOME_EXAM.md

parent 6cb8d388
Branches
No related tags found
No related merge requests found
...@@ -199,6 +199,9 @@ Showcase of EBNF: ...@@ -199,6 +199,9 @@ Showcase of EBNF:
if (c > 0) { if (c > 0) {
true true
} }
else {
false
}
} }
fn main() { fn main() {
...@@ -374,7 +377,7 @@ let a = 2; ...@@ -374,7 +377,7 @@ let a = 2;
### Assign expression ### Assign expression
```math ```math
\frac{<e, σ> → n}{<mv = e,σ> → σ'[mv=n]} \frac{<e, σ> → n}{<e, σ> → σ'[mv=n]}
``` ```
Where the expression also can be a boolean or function. Where the expression also can be a boolean or function.
...@@ -408,7 +411,7 @@ else { ...@@ -408,7 +411,7 @@ else {
``` ```
``` rust ``` rust
let a = 0; let mut a = 0;
while a < 10 { while a < 10 {
// something that should loop 10 times // something that should loop 10 times
a = a + 1; a = a + 1;
...@@ -435,6 +438,9 @@ fn func(x:i32, y:i32) -> i32 { ...@@ -435,6 +438,9 @@ fn func(x:i32, y:i32) -> i32 {
if (c > 0) { if (c > 0) {
true true
} }
else {
false
}
} }
fn main() { fn main() {
...@@ -454,6 +460,7 @@ fn func(x:i32, y:i32) -> i32 { ...@@ -454,6 +460,7 @@ fn func(x:i32, y:i32) -> i32 {
- →, evaluates - →, evaluates
- c, command - c, command
- v, variable - v, variable
- mv, mutable variable
- e, expression - e, expression
- t, type - t, type
...@@ -518,7 +525,7 @@ false < 2; // Type missmatch ...@@ -518,7 +525,7 @@ false < 2; // Type missmatch
``` ```
```math ```math
\frac{<e,σ> → \&text{mut } t}{<*e,σ> → \text{mut} t} \frac{<e,σ> → \&\text{mut } t}{<*e,σ> → \text{mut} t}
``` ```
```math ```math
...@@ -537,20 +544,23 @@ let d:bool = *b; // <-- Type missmatch ...@@ -537,20 +544,23 @@ let d:bool = *b; // <-- Type missmatch
\frac{<f(e), σ> → t}{<f, σ> → \text{ret } t} \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 ``` rust
fn func() -> i32 { fn example1() -> i32 {
1+3 1+3 // This is okay return type
} }
fn main() { fn example2() -> i32 {
let a = func(); true // This is a type missmatch with what type is expected to return
let b:bool = a(); // Type missmatch
} }
``` ```
### Let expression ### Let expression
```math ```math
\frac{<e, σ> → t, σ'}{<v := e,σ> → σ'[v:=n]} \frac{<e, σ> → t}{<{/text{let } v = e,σ> → <(), σ[v=t]>}
``` ```
``` rust ``` rust
let a:i32 = 1; let a:i32 = 1;
...@@ -598,13 +608,13 @@ else { ...@@ -598,13 +608,13 @@ else {
``` ```
``` rust ``` rust
let a = 0; let mut a = 0;
while a < 10 { while a < 10 {
// something that should loop 10 times // something that should loop 10 times
a = a + 1; a = a + 1;
} }
let a = 0; let mut a = 0;
while a * 10 { // Type missmatch while a * 10 { // Type missmatch
// something that should loop 10 times // something that should loop 10 times
a = a + 1; a = a + 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment