Skip to content
Snippets Groups Projects
Commit 82663289 authored by Wilma Krutrök's avatar Wilma Krutrök
Browse files

Illeagal examples added

parent 7c04b586
No related branches found
No related tags found
No related merge requests found
......@@ -230,11 +230,11 @@ Bool
fn test1(x: i32, y: i32) -> i32 {
if x < y {
if x > 0 {
- x + (2 * y);
- x + (2 * y)
};
x + y
} else {
- x - (2 * y);
- x - (2 * y)
}
};
fn test2(x: bool) -> bool {
......@@ -253,19 +253,54 @@ Bool
}
```
#### Illeagal examples
Three examples that will be rejected by the compiler:
```rust
fn a(x: bool, y: bool) {
x || y
}
```
No return type.
```rust
fn a(x: bool) -> bool {
x
};
fn main() -> () {
a();
}
```
No argument given in functioncall.
```rust
fn a(x: i32, y: i32) -> bool {
if x > y {
true
}
else x < y {
false
}
}
```
Expressions not allowed in else statment.
#### Coverage
The following bullet points are covered by the parser
- Two different function definitions (with arguments and return type or without arguments and return type)
- Let and mutable let
- Assignments
- Functioncalls
- If with or without else
- While
- Expressions
- Expressions (parenthesized expressions, prefix, several operands, precedence)
- Types: bool, i32 and unit
All statements have explicit types.
#### Future implementation
In the future could the following things be implemented to allow the parser to accept more programs
- Function definition with arguments but no return type or no arguments but return type
- Else if
- Other loops than while
......@@ -274,6 +309,7 @@ All statements have explicit types.
- Functions not needed to be decleared in specific order
- Global assignments
- Shadowing
- Pretty printing
Currently it is needed to seperate statements with ";" (except for the last one) for the parser to interpret it as a vector. This would be nice to rewrite in the future.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment