-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
19 REALs #51
19 REALs #51
Conversation
Parsing REALsREAL tokens are going to be picked up by Which delegates the parsing to So it doesn't look like any additional work is needed here to have REAL tokens parsed as Literal Exprs. |
Resolving REALsOperationsREALs can be operated on by any operator that takes numeric types, so our type-checking for Binary and Unary Exprs will have to be updated. First, unary negative: Then the equality operators, The comparison operators: And lastly the arithmetic operators: It's a lot of |
This enables expectTypeElseError() to accept multiple type arguments, without changing its behavior for single type arguments.
To make the above changes, we had to undo a few uses of our Let's overload our The And use it again where we want to match for multiple types: [529a658] |
Interpreting REALsThere's not much smarts in our interpreter; it evaluates the operands, and passes them to the operator. If our type-checking is correct, Python's operator implementation gets us the rest of the way. And we have support for REALs! |
Type subcategoriesBefore wrapping up here, let's make things a bit easier to read (but more abstract). We have some lines so long we have to stretch them to three lines, like: Let's introduce subcategories of TYPE to make this easier. We have the NUMERIC types: These can be used with arithmetic and comparison operators. Then we have the EQUATABLEs: These can be used with the equality operators. And lastly we add these to the remaining types to get our trusty TYPES: Yep, TYPES is now a tuple instead of a string, but this otherwise doesn't affect our code. |
Now we can use them in our typechecks: [2bb8aa7] Python's |
Okay, time to get to REALs (Issue #4).
Scanning REALs
Let's start with adding the REAL type to
builtin.py
:https://github.com/nyjc-computing/pseudo/blob/b76de00482a2799c7190f92596343b3dcce4d4c8/builtin.py#L103
And then scanning them:
https://github.com/nyjc-computing/pseudo/blob/948ffffd05253150224de0ccd62d0de5c55c16c6/scanner.py#L35-L45
When we reach the end of the digit sequence, we check for a
.
; if there isn't one, we return an INTEGER. If there's one, we continue scanning another digit sequence to get a REAL.And we make sure to pass the correct token type:
https://github.com/nyjc-computing/pseudo/blob/948ffffd05253150224de0ccd62d0de5c55c16c6/scanner.py#L109-L114