Skip to content
Snippets Groups Projects
Commit e5c3734c authored by Abrikot's avatar Abrikot
Browse files

Adding files

parent 5015c123
Branches home_exam
No related tags found
No related merge requests found
Pipeline #185 failed
...@@ -8,7 +8,7 @@ https://gitlab.com/Abrikot/rust-parser ...@@ -8,7 +8,7 @@ https://gitlab.com/Abrikot/rust-parser
- Give an as complete as possible EBNF grammar for your language - Give an as complete as possible EBNF grammar for your language
The EBNF grammar file can be found here: https://gitlab.com/Abrikot/rust-parser/blob/master/ebnf.txt. The EBNF grammar file can be found here: https://gitlab.henriktjader.com/Abrikot/d7050e/blob/home_exam/ebnf.txt.
``` ```
(* Basic definitions *) (* Basic definitions *)
...@@ -149,7 +149,7 @@ Every requirement in the README.md seems to be fulfilled. I have done everything ...@@ -149,7 +149,7 @@ Every requirement in the README.md seems to be fulfilled. I have done everything
- Give an as complete as possible Structural Operational Semantics (SOS) for your language - Give an as complete as possible Structural Operational Semantics (SOS) for your language
The SOS rules can be found here: https://gitlab.com/Abrikot/rust-parser/blob/master/SOS%20rules.pdf. The SOS rules can be found here: https://gitlab.henriktjader.com/Abrikot/d7050e/blob/home_exam/SOS%20rules.pdf.
- Explain (in text) what an interpretation of your example should produce, do that by dry running your given example step by step. Relate back to the SOS rules. You may skip repetitions to avoid cluttering. - Explain (in text) what an interpretation of your example should produce, do that by dry running your given example step by step. Relate back to the SOS rules. You may skip repetitions to avoid cluttering.
...@@ -181,7 +181,7 @@ I implemented all of this alone. ...@@ -181,7 +181,7 @@ I implemented all of this alone.
- Give an as complete as possible set of Type Checking Rules for your language (those rules look very much like the SOS rules, but over types not values). - Give an as complete as possible set of Type Checking Rules for your language (those rules look very much like the SOS rules, but over types not values).
The type checking rules can be found here: https://gitlab.com/Abrikot/rust-parser/blob/master/Type%20checking%20rules.pdf. The type checking rules can be found here: https://gitlab.henriktjader.com/Abrikot/d7050e/blob/home_exam/Type%20checking%20rules.pdf.
- Demonstrate each "type rule" by an example. - Demonstrate each "type rule" by an example.
......
File added
File added
ebnf.txt 0 → 100644
(* Basic definitions *)
letter = "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" ;
digit_excluding_zero = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
digit = "0" | digit_excluding_zero;
number = digit_excluding_zero | { digit };
boolean = "true" | "false";
terminal = number | boolean;
primitive_type = "i32" | "bool";
type = [ &, [ "mut" ], type] | primitive_type;
(* Operations *)
binary_operator = "+"
| "-"
| "*"
| "/"
| "%"
| "&&"
| "||"
| "=="
| "^"
| "<"
| "!=";
binary_operation = (parenthesized_expression | unary_operation | terminal | variable), binary_operator, expression;
unary_operator = "-"
| "!";
unary_operation = unary_operator, expression;
(* Expressions *)
parenthesized_expression = "(", expression, ")";
expression = block
| if
| function_call
| binary_operation
| unary_operation
| parenthesized_expression
| terminal
| variable
| reference
| dereference;
reference = "&", ["mut"], expression;
dereference = "*", expression;
(* Variables *)
object_name = { letter | "_" };
variable = object_name;
declaration = "let", variable, ":", type, "=", expression;
(* Statements *)
left_hand_side = variable
| ("&", left_hand_side)
| ("*", left_hand_side);
assignment = left_hand_side, "=",expression;
non_returning_statement = (while | declaration | assignment | expression), ";";
returning_statement = "return", expression, ";";
(* Blocks *)
block = "{", [{ non_returning_statement }], [ returning_statement ], "}";
(* Conditionals *)
if = "if", expression, block, ["else", block];
while = "while", expression, block;
(* Functions *)
parameters_list = [{ "mut", object_name, ":", type }];
return_type = ["->", primitive_type];
function = "fn", object_name, "(", parameters_list, ")", return_type, block;
(* Functions calls *)
arguments_list = [expression, [{",", expression}]];
function_call = object_name, "(", arguments_list, ")";
(* File *)
file = [{ function }];
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment