The parser has been implemented using an LR(1) parser generator, [lalrpop](https://github.com/lalrpop/lalrpop). It's a strong tool that offers your code to be DRY and have a readeble grammar from the beginning. It also offers macros which have been used to make the the code less repetetive, more readeble and to implement precedence.
To write the parser the documention has been sufficient but examples from both the documentation and the lalrpop repo has been used.
Above descirbed EBNF and showcase defines a minimal subset of Rust, including
- Function declaration, with excplicit return type either void (NONE) or primitive type
- Primitive types are i32 and boolean
...
...
@@ -186,31 +190,122 @@ For furture development
- Compare your solution to the requirements (as stated in the README.md). What are your contributions to the implementation.
Structural Operational Semantics (SOS)
Symbolx:
Symbols:
- σ, state
- σ', derived state
- ⇓, evaluates
- c, command
- x, variable
- e, expression
- b, boolean expression
An expression can be either a
- b, boolean
- n, number
- f, function
Function sequence
$<f,σ>⇓σ'$
```rust
fnmain(){
test();
}
```
The function call moves the current state, $σ$ to the new derived state $σ'$ in the function, test()'s context.
A sequence is a composition of commands where the first command is first executed then the second command. Otherwise the intermediate step, $σ'$ would be lost.
letc:i32=test();// test() explicit return of type i32
```
For let commands, if the variable is already declared the state $σ$ will be changed to the one of the second command, state $σ'$, the variable will be lost. Otherwise the variable will be assigned to the state, $σ$.
Assignment expression
$\frac{}{<x:= e,σ> ⇓ σ[x := e]}$
```rust
x=1;
x=true;
x=test();
```
For assignment, when the variable is assigned to a number, boolean or function the variable and corresponding rhs is moved to the same state.
Return
$\frac{<f,σ>⇓σ}{<return:e,σ> ⇓ σ[return : e]}$
```rust
fnmain()->i32{
return1+1;
}
```
At explicit return the expression is moved to the state of the function.