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:
if (c > 0) {
true
}
else {
false
}
}
fn main() {
......@@ -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;
......@@ -435,6 +438,9 @@ fn func(x:i32, y:i32) -> i32 {
if (c > 0) {
true
}
else {
false
}
}
fn main() {
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment