diff --git a/HOME_EXAM.md b/HOME_EXAM.md index 7634c1e1cf762ce354e4dae5a01c68dae9d1efa6..366270e04f7377cf0e47a570d52d08be738de906 100644 --- a/HOME_EXAM.md +++ b/HOME_EXAM.md @@ -2,9 +2,11 @@ - Fork this repo and put your answers (or links to answers) in THIS file. +_Answers can be found at the end of this file_ + ## Your repo -- Link to your repo here: +- Link to your repo here: https://github.com/wilkru-7/D7050E ## Your syntax @@ -69,3 +71,170 @@ Comment on the alignment of the concrete course goals (taken from the course des - Code optimization and register allocation. Machine code generation for common architectures. [Both LLVM/Crane-Lift does the "dirty work" of backend optimization/register allocation leveraging the SSA form of the LLVM-IR] Comment on additional things that you have experienced and learned throughout the course. + +# Home Exam - Answers by Wilma Krutrök +In the following sections will the bullet points above be covered. The answers will be based on the code attached. + +## Syntax +The implemented langugage is desciribed usign EBNF grammar below. The language is implemented using lalrpop. Note that "?" means optional and when a part ends with "s" for example "programs" is it a vector containing one or more program (same as program+). + + +```ebnf +Program + :Programs + |Function + |Decl + |Expr + ; +``` + +```ebnf +Stmt + :Function + |"if" Expr BlockExpr "else"? BlockExpr? + |"while" Expr BlockExpr + |Decl + |Expr + ; +``` + +```ebnf +Function + :"fn" Id "(" Args ")" "->" Type BlockExpr + |"fn" Id "()" "->" "()" BlockExpr + ; +``` + +```ebnf +BlockExpr + :"{" Stmts "}" + ; +``` + +```ebnf +Decl + :"let" Id ":" Type? "=" Expr + |"let mut" Id ":" Type? "=" Expr + |Id "=" Expr + ; +``` + +```ebnf +Arg + :Id ":" Type + ; +``` + +```ebnf +Expr + :Expr ExprOp Factor + |Expr LogicOp Factor + |Id "(" Exprs ")" + |PrefixOp "(" Expr ")" + |Factor + ; +``` + +```ebnf +Prefix + :"-" + ; +``` + +```ebnf +ExprOp + :"+" + |"-" + ; +``` + +```ebnf +LogicOp + :"&&" + |"||" + |"<" + |">" + |"<=" + |">=" + |"!=" + |"==" + ; +``` + +```ebnf +Factor + :Factor FactorOp Term + |Term + ; +``` + +```ebnf +FactorOp + :"*" + |"/" + ; +``` + +```ebnf +Term + :PrefixOp NumOrId + :NumOrId + :"(" Expr ")" + ; +``` + +```ebnf +PrefixOp + :"-" + :"!" + ; +``` + +```ebnf +Type + :"i32" + |"bool" + |"()" + ; +``` + +```ebnf +NumOrId + :Num + |Id + |Bool + ; +``` + +```ebnf +Num + :[0-9]+ + ; +``` + +```ebnf +Id + :([a-z]|[A-Z]|_)([a-z]|[A-Z]|[0-9]|_)* + ; +``` + +```ebnf +Bool + :"true" + |"false" + ; +``` + +Showcase +```rust + +``` +## Semantics + +## Type checker + +## Borrow checker + +## Conclusion + +