From 53f4721cccf41b00c7cffb02354e7178003f6381 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 4 Sep 2024 21:38:36 -0700 Subject: [PATCH] Add explanation for errors --- README.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/README.md b/README.md index 7ef995a..046539d 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,14 @@ The code for Component and Basis use the same lexer. Component is mainly differe ## Interactive interpreter ![image](https://github.com/user-attachments/assets/3d1978d6-c3b7-4954-9ba5-6b8958e396b1) +## Keywords + +- `int` converts types into NumericIntLiteral if possible +- `dec` converts types into NumericDecLiteral if possible + +## Constants +- `e` Euler's number + ## Basic Math Operations Add two numbers together. @@ -77,5 +85,68 @@ Create an addition function called `foo`. ## Error Handling +Errors that occur in the interactive interpreter cause the line being interpreted to crash. When this happens, one of the following error messages will be displayed. + +#### Assignment Type Mismatch [E1] + +An Assignment Type Mismatch happens when you try to assign a value to an existing variable of a different type. In the following example, the variable `a` is created as a NumericIntLiteral type. Then the value `0.8` is attempted to be assigned the variable `a` but because `0.8` is of the type NumericDecLiteral, it fails with an Assignment Type Mismatch error. This means that variables are statically typed and cannot be changed during runtime. + +``` +> 1 a = +-> 1 + +> 4 5 / a = +Error: Assignment Type Mismatch [E1] +0.8 a = + ^^^ cannot assign value 0.8 of type to a variable of type +``` + +#### Wrong Type [E2] + +A Wrong Type error happens when you try to call an operation or a function on one or more variables of the wrong type. Here is an example of an identifier being used before it has been assigned. Since it does not get swapped out for a value, since it hasn't been assigned, it has the type Identifier and therefore is the wrong type. In the future, this will also happen for math operations on the type String. + +``` +> a 1 + +Error: Wrong Type [E2] +a 1 + +^ value is not a or +``` + +#### Invalid Type Cast [E3] + +An Invalid Type Cast happens when you try to cast from type to type but there is not an operation where this is possible. Similar to the Wrong Type error, the example below shows how an Identifier that has not been assigned a value, is being attempted to cast to both a NumericDecLiteral with the keyword `dec` and a NumericIntLiteral with the keyword `int`. Since there has been no assignment to the variable `a`, it will not get swapped out for a value, and the type cannot be cast to either. + +``` +> a dec +Error: Invalid Type Cast [E3] +a dec + ^^^ Cannot convert to + +> a int +Error: Invalid Type Cast [E3] +a int + ^^^ Cannot convert to +``` + +#### Stack Empty [E4] +The Stack Empty error happens when the function or operation that has been called requires more arguments than are currently on the stack. This is an indication that not enough variables where provided. In the example below, a single NumericIntLiteral has been added to the stack and then the Addition operation has been called. This gives and error because the Addition operation requires two arguments. + +``` +> 1 + +Error: Stack Empty [E4] +``` + +#### Operation Not Implemented [E5] + +The Operation Not Implemented error occurs when a non-identifier symbol has been parsed that has not gotten functionality yet. Symbol here meaning one or many characters (e.g. `foo` or `123`). Since symbols that are not keywords or existing identifiers get read as identifiers (so long they follow the identifier rules), there are few things that trigger the Operation Not Implemented error. The one class of symbols that do cause this error are characters like `#` and `$` which have not been assigned any operation. + +``` +> # +Error: Operation Not Implemented [E5] + +> $ +Error: Operation Not Implemented [E5] +``` + ![image](https://github.com/user-attachments/assets/993e8eb3-0ca2-4a20-8b30-37dd405992bd)