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

Update HOME_EXAM.md

parent 0f82daa9
No related branches found
No related tags found
No related merge requests found
...@@ -222,131 +222,160 @@ illegal stuff; ...@@ -222,131 +222,160 @@ illegal stuff;
## Your semantics ## Your semantics
```
- Give a (simplified) Structural Operational Semantics (SOS) for your language. You don't need to detail rules that are similar (follow the same pattern). Regarding variable environment (store) you may omit details as long as the presentation is easy to follow. - Give a (simplified) Structural Operational Semantics (SOS) for your language. You don't need to detail rules that are similar (follow the same pattern). Regarding variable environment (store) you may omit details as long as the presentation is easy to follow.
- Explain (in text) what an interpretation of your example should produce, do that by dry running your given example step by step. Relate back to the SOS rules. You may skip repetitions to avoid cluttering.
```
##### Symbols: ##### Symbols:
- σ, state - σ, state
- σ', derived state - σ', changed state
- , evaluates - , evaluates
- c, command - c, command
- v, variable - v, variable
- e, expression - e, expression
- t, type
##### Expression can be either a ##### Expression can be either a
- b, boolean - b, boolean
- i, integer - n, number
- f, function - f, function
##### Types are
- i32, integer
- bool, boolean
- (), Unit
- &t, reference to type
- &mut t, mutable reference to type
- *t, dereference to type
### Function sequence
```math
<f, σ>⇓σ'
```
``` rust
fn main() {
func();
}
```
### Command sequence ### Command sequence
```math ```math
\frac{<c_1,σ> σ' <c_2,σ'> σ''}{<c_1;c_2,σ> σ''} \frac{<c_1,σ> σ' <c_2,σ'> σ''}{<c_1;c_2,σ> σ''}
``` ```
``` rust ``` rust
func(); let a = 1;
let a:bool = true; let b = 2;
``` ```
### Operands for integer expressions ### Operands for integer expressions
```math ```math
\frac{<e_1,σ> ⇓ i_1 <e_2, σ> ⇓ i_2}{<e_1 - e2, σ> ⇓ i_1 \text{ minus } i_2} \frac{<e_1,σ> → n_1 <e_2, σ> → n_2}{<e_1 - e2, σ> → n_1 \text{ minus } n_2}
``` ```
Above is a minus operation of two integers, following integer expressions can be described in the same way:
- +, Addition
- *, Multiplication
- /, Division
- ">", Greater than
- ">=", Greater than or equals
- "<", Less than
- "<=", Less than or equals
- "==", Equal
- "!=", Not equal
``` rust ``` rust
8 / 4 = 2; (3+5)*(4-2);
5 >= 2;
2 == 2;
``` ```
Above is a minues operation of two integers, following integer expressions can be described in the same way:
- -, minus
- *, multiplication
- /, division
- ">", greater than
- ">=", greater than or equals
- "<", less than
- "<=", less than or equals
- "==", equal
- "!=", not equal
### Operands for boolean expressions ### Operands for boolean expressions
```math ```math
\frac{<e_1,σ> b_1 <e_2, σ> b_2}{<e_1 == e_2, σ> b_1 \text{ equal } b_2} \frac{<e_1,σ> b_1 <e_2, σ> b_2}{<e_1 == e_2, σ> b_1 \text{ equal } b_2}
``` ```
Above is an equals operation of two expessions, following boolean expressions can be described in the same way: Above is an equals operation of two expessions, following boolean expressions can be described in the same way:
- "!=", not equal - "!=", Not equal
- "&&", and - "&&", And
- "||", or - "||", Or
``` rust
false != true;
true || false;
```
### Reference and Dereference ### Reference and Dereference
```math ```math
\frac{<e,σ> ⇓ v}{<\&e,σ> ⇓ \text{ ref } v} \frac{<e,σ> → v}{<\&e,σ> → \text{ ref } v}
```
A reference to some expression
``` rust
&a;
``` ```
```math ```math
\frac{<e,σ> ⇓ v}{<\&\text{ mut }e,σ> ⇓ \text{ ref mut } v} \frac{<e,σ> → v}{<\&\text{ mut }e,σ> → \text{ ref mut } v}
```
A mutable reference to some expression
``` rust
&mut a;
``` ```
```math ```math
\frac{<e,σ> ⇓ v}{<*e,σ> ⇓ \text{ deref } v} \frac{<e,σ> → v}{<*e,σ> → \text{ deref } v}
```
Dereference of a referenced expression
``` rust
*a;
``` ```
### Function call expression ### Function call expression
```math ```math
<e, σ> ⇓ \text{ret } e \frac{<f(e_1,e_2,...,e_n),σ> → <v,σ'>; <e_1,σ> → v; ...; <e_n, σ>→ v}{<f, σ> → v}
```
``` rust
fn func() -> i32 {
1+3
}
fn main() {
let a = func();
}
``` ```
### Let expression ### Let expression
```math ```math
\frac{<v, σ> ⇓ t<\text{let } v:t, σ> ⇓ σ'}{<\text{let } v : t, σ> ⇓ σ[v : t]} \frac{<e, σ> → v, σ'}{<\text{let id} = e, σ> → σ'[\text{id} = e]}
```
``` rust
let a = 1;
``` ```
Declares the variable $`v`$ with type $`t`$ to current scope.
### Assign expression ### Assign expression
```math ```math
{<v := e, σ> ⇓ σ[v := e]} \frac{<e, σ> → v, σ'}{<\text{id} = e, σ> → σ'[\text{id} = e]}
{\langle \text{test} \rangle} ```
``` rust
a = 0;
``` ```
### If true/false expression ### If true/false expression
```math ```math
\frac{<b, σ> ⇓ true <c_1, σ> ⇓ σ'}{<\text{if } b \text{ then }c_1 \text{ else } c_2,σ> ⇓ σ'} \frac{<b, σ> → true <c_1, σ> → σ'}{<\text{if } b \text{ then }c_1 \text{ else } c_2,σ> → σ'}
```
```math
\frac{<b, σ> → false <c_2, σ> → σ'}{<\text{if } b \text{ then }c_1 \text{ else } c_2,σ> → σ''}
``` ```
### While expression ``` rust
if 3 > 5 {
### Return expression func();
}
else {
anotherfunc();
}
```
- Explain (in text) what an interpretation of your example should produce, do that by dry running your given example step by step. Relate back to the SOS rules. You may skip repetitions to avoid cluttering. ### While expression
```math
\frac{<b, σ> → true <c, σ> → σ' <\text{while } b \text{ do } c, σ'> → σ''}{<\text{while } b \text{ do } c, σ> → σ''}
```
```math
\frac{<b, σ> → false}{<\text{while } b \text{ do } c, σ> → σ}
```
``` rust
let a = 0;
while a < 10 {
// something that should loop 10 times
a = a + 1;
}
```
```
- For your implementation, give a program (or set of test programs) that cover all the semantics of your language that you have successfully implemented. (Maybe a subset of the input language accepted by the grammar.) - For your implementation, give a program (or set of test programs) that cover all the semantics of your language that you have successfully implemented. (Maybe a subset of the input language accepted by the grammar.)
- Compare your solution to the requirements (as stated in the README.md). What are your contributions to the implementation. - Compare your solution to the requirements (as stated in the README.md). What are your contributions to the implementation.
```
## Your type checker ## Your type checker
- Give a simplified set of Type Checking Rules for your language (those rules look very much like the SOS rules, but over types not values). Also here you don't need to detail rules that are similar (follow the same pattern). - Give a simplified set of Type Checking Rules for your language (those rules look very much like the SOS rules, but over types not values). Also here you don't need to detail rules that are similar (follow the same pattern).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment