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

Added EBNF

parent cd1bfd12
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment