Skip to content
Snippets Groups Projects
Commit 4d89b502 authored by David Eriksson's avatar David Eriksson
Browse files

Update HOME_EXAM.md

parent 3e57cda5
No related branches found
No related tags found
1 merge request!1Draft: Homeexam
...@@ -4,19 +4,240 @@ ...@@ -4,19 +4,240 @@
## Your repo ## Your repo
- Link to your repo here: - Link to your repo here: **_Insert github link here_**
## Your syntax ## Your syntax
- Give an as complete as possible EBNF grammar for your language. > - Give an as complete as possible EBNF grammar for your language.
- Give an example that showcases all rules of your EBNF. The program should "do" something as used in the next exercise. Program
```ebnf
- For your implementation, show that your compiler successfully accepts the input program. : Func Program
| Func
- Give a set of examples that are syntactically illegal, and rejected by your compiler. ;
```
- Compare your solution to the requirements (as stated in the README.md). What are your contributions to the implementation. Func
```ebnf
: "fn" Id Params "->" Type Block
| "fn" Id Params Block
;
```
Params
```ebnf
: "()"
| "(" [ "," ], Param ")"
;
```
Param
```ebnf
: "mut" Id ":" Type
| Id ":" Type
;
```
Block
```ebnf
: "{" StmtSeq* Stmt "}"
| "{" StmtSeq* "}"
;
```
StmtSeq
```ebnf
: ";"
| Stmt ";"
| StmtBlock
;
```
Stmt
```ebnf
: "let" Id ":" Type "=" Expr
| "let" Id ":" Type
| "let" Id "=" Expr
| "let" Id
| "let" "mut" Id ":" Type "=" Expr
| "let" "mut" Id ":" Type
| "let" "mut" Id "=" Expr
| "let" "mut" Id
| Expr "=" Expr
| Expr1
;
```
StmtBlock
```ebnf
: "while" Expr Block
| "if" Expr Block "else" Block
| "if" Expr Block
| Block
;
```
Expr
```ebnf
: ExprBlock
| Expr1
;
```
ExprBlock
```ebnf
: "if" Expr Block "else" Block
| Block
;
```
Expr1
```ebnf
: Expr1 LoCode Expr2
| Expr1 ArCode Expr2
| Expr2
;
```
Expr2
```ebnf
: Expr2 FactorCode Lit
| Lit
;
```
Lit
```ebnf
: Id Exprs
| ArCode Lit
| "!" Lit
| Bool
| Num
| Id
| "&" Lit
| "&mut" Lit
| "*" Lit
| "(" Expr ")"
;
```
Exprs
```ebnf
: "()"
| "(" [ "," ], Expr1 ")"
```
LoCode
```ebnf
: "&&"
| "||"
| "=="
| "!="
| ">"
| "<"
| ">="
| "<="
;
```
ArCode
```ebnf
: "+"
| "-"
;
```
FactorCode
```ebnf
: "*"
| "/"
;
```
Type
```ebnf
: "i32"
| "bool"
| "()"
| "&" Type
| "&mut" Type
;
```
Num
```ebnf
: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
;
```
Id
```ebnf
: (LetterLow | LetterHigh | "_")+ (LetterLow | LetterHigh | Num | "_")*
;
```
Bool
```ebnf
: "true"
| "false"
;
```
LetterHigh
```ebnf
: "A" | "B" | "C" | "D" | "E" | "F" | "G"
| "H" | "I" | "J" | "K" | "L" | "M" | "N"
| "O" | "P" | "Q" | "R" | "S" | "T" | "U"
| "V" | "W" | "X" | "Y" | "Z"
;
```
LetterLow
```ebnf
: "a" | "b" | "c" | "d" | "e" | "f" | "g"
| "h" | "i" | "j" | "k" | "l" | "m" | "n"
| "o" | "p" | "q" | "r" | "s" | "t" | "u"
| "v" | "w" | "x" | "y" | "z"
;
```
Accepted code
```Rust
fn main() {
let mut a = 3;
let b = &mut a;
*b = 1;
while a <= 3 {
*b = add(*b, 1);
}
let c = a / 3;
}
fn add(a:i32, b:i32) -> i32 {
a+b
}
```
> - Give an example that showcases all rules of your EBNF. The program should "do" something as used in the next exercise.
> - For your implementation, show that your compiler successfully accepts the input program.
**Accepted code**
```Rust
fn main() {
let mut a = 3;
let b = &mut a;
*b = 1;
while a <= 3 {
*b = add(*b, 1);
}
let c = a / 3;
}
fn add(a:i32, b:i32) -> i32 {
a+b
}
```
> - Give a set of examples that are syntactically illegal, and rejected by your compiler.
**Rejected Code**
```Rust
```
> - Compare your solution to the requirements (as stated in the README.md). What are your contributions to the implementation.
I have fullfilled all of the of the requirements for a minimal subset of Rust such as:
* Functions
* Statements
* Expressions
* Primitive types and literals
* Returns
* References and Dereferences
## Your semantics ## Your semantics
...@@ -46,14 +267,6 @@ ...@@ -46,14 +267,6 @@
- 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 LLVM/Crane-Lift backend (optional)
- Let your backend produce LLVM-IR/Crane Lift IR for an example program (covering the translations implemented).
- Describe the translation process, and connect back to the generated IR.
- Compare your solution to the requirements (as stated in the README.md). What are your contributions to the implementation.
## Overall course goals and learning outcomes. ## Overall course goals and learning outcomes.
Comment on the alignment of the concrete course goals (taken from the course description) to the theory presented, work You have done and knowledge You have gained. (I have put some comments in [...]). Comment on the alignment of the concrete course goals (taken from the course description) to the theory presented, work You have done and knowledge You have gained. (I have put some comments in [...]).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment