From d26435b52909fa9ce167186a63d75b2cd4d8c6a8 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 29 Jan 2023 13:36:48 +0200 Subject: [PATCH] Expressions - Added enum type `NumberLiteralEncoding` mimicking that of D's integer literals encoding variations - Added an instance of `NumberLiteralEncoding` to `NumberLiteral` along with a `getEncoding()` method to fetch said field Parser - Added TODO --- source/tlang/compiler/parsing/core.d | 1 + source/tlang/compiler/symbols/expressions.d | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/source/tlang/compiler/parsing/core.d b/source/tlang/compiler/parsing/core.d index b3638a49..042677fe 100644 --- a/source/tlang/compiler/parsing/core.d +++ b/source/tlang/compiler/parsing/core.d @@ -1114,6 +1114,7 @@ public final class Parser if (symbol == SymbolType.NUMBER_LITERAL) { /* TODO: Do number checking here to get correct NUmberLiteral */ + // TODO: Insert code here for handling various different encodings NumberLiteral numberLiteral = new NumberLiteral(getCurrentToken().getToken()); /* Add expression to stack */ diff --git a/source/tlang/compiler/symbols/expressions.d b/source/tlang/compiler/symbols/expressions.d index 45c25ddf..d4ae2169 100644 --- a/source/tlang/compiler/symbols/expressions.d +++ b/source/tlang/compiler/symbols/expressions.d @@ -85,9 +85,18 @@ public class BinaryOperatorExpression : OperatorExpression } } +public enum NumberLiteralEncoding +{ + SIGNED_INTEGER, + UNSIGNED_INTEGER, + SIGNED_LONG, + UNSIGNED_LONG +} + public class NumberLiteral : Expression { private string numberLiteral; + private NumberLiteralEncoding encoding; /* TODO: Take in info like tyoe */ this(string numberLiteral) @@ -100,9 +109,14 @@ public class NumberLiteral : Expression return numberLiteral; } + public NumberLiteralEncoding getEncoding() + { + return encoding; + } + public override string toString() { - return "[numberLiteral: "~numberLiteral~"]"; + return "[numberLiteral: "~numberLiteral~" ("~to!(string)(encoding)~")]"; } }