diff --git a/compiler/Compiler/Generator.cs b/compiler/Compiler/Generator.cs index b2acf3a..2bc648c 100644 --- a/compiler/Compiler/Generator.cs +++ b/compiler/Compiler/Generator.cs @@ -1,5 +1,4 @@ -using System.Globalization; -using System.Text; +using System.Text; namespace Compiler; @@ -84,7 +83,6 @@ public sealed class Generator(List nodes) return node switch { NodeExpressionBoolLiteral expression => EmitExpressionBoolLiteral(expression), - NodeExpressionFloatLiteral expression => EmitExpressionFloatLiteral(expression), NodeExpressionIntLiteral expression => EmitExpressionIntLiteral(expression), NodeExpressionStringLiteral expression => EmitExpressionStringLiteral(expression), NodeExpressionIdent expression => EmitExpressionIdent(expression), @@ -96,11 +94,6 @@ public sealed class Generator(List nodes) return expression.Value.Value ? "1" : "0"; } - private string EmitExpressionFloatLiteral(NodeExpressionFloatLiteral expression) - { - return expression.Value.Value.ToString(CultureInfo.InvariantCulture); - } - private string EmitExpressionIntLiteral(NodeExpressionIntLiteral expression) { return expression.Value.Value.ToString(); diff --git a/compiler/Compiler/Parser.cs b/compiler/Compiler/Parser.cs index 820574a..6a974f4 100644 --- a/compiler/Compiler/Parser.cs +++ b/compiler/Compiler/Parser.cs @@ -83,11 +83,6 @@ public sealed class Parser(List tokens) return new NodeExpressionIntLiteral(TokensFrom(startIndex), intLiteral); } - if (TryExpectFloatLiteral(out var floatLiteral)) - { - return new NodeExpressionFloatLiteral(TokensFrom(startIndex), floatLiteral); - } - if (TryExpectStringLiteral(out var stringLiteral)) { return new NodeExpressionStringLiteral(TokensFrom(startIndex), stringLiteral); @@ -227,19 +222,6 @@ public sealed class Parser(List tokens) return false; } - private bool TryExpectFloatLiteral([NotNullWhen(true)] out TokenFloatLiteral? floatLiteral) - { - if (Peek() is TokenFloatLiteral token) - { - Consume(); - floatLiteral = token; - return true; - } - - floatLiteral = null; - return false; - } - private bool TryExpectStringLiteral([NotNullWhen(true)] out TokenStringLiteral? stringLiteral) { if (Peek() is TokenStringLiteral token) @@ -293,15 +275,15 @@ public abstract class NodeDefinition(List tokens) : Node(tokens); public sealed class NodeDefinitionFunc(List tokens, TokenIdent name, List parameters, NodeStatement body, NodeType returnType) : NodeDefinition(tokens) { - public TokenIdent Name = name; - public List Parameters = parameters; - public NodeStatement Body = body; - public NodeType ReturnType = returnType; + public readonly TokenIdent Name = name; + public readonly List Parameters = parameters; + public readonly NodeStatement Body = body; + public readonly NodeType ReturnType = returnType; public sealed class Param(List tokens, TokenIdent name, NodeType type) : Node(tokens) { - public TokenIdent Name = name; - public NodeType Type = type; + public readonly TokenIdent Name = name; + public readonly NodeType Type = type; } } @@ -309,40 +291,35 @@ public abstract class NodeStatement(List tokens) : Node(tokens); public sealed class NodeStatementBlock(List tokens, List statements) : NodeStatement(tokens) { - public List Statements = statements; + public readonly List Statements = statements; } public sealed class NodeStatementFuncCall(List tokens, NodeExpression func, List parameters) : NodeStatement(tokens) { - public NodeExpression Func = func; - public List Parameters = parameters; + public readonly NodeExpression Func = func; + public readonly List Parameters = parameters; } public abstract class NodeExpression(List tokens) : Node(tokens); public sealed class NodeExpressionIntLiteral(List tokens, TokenIntLiteral value) : NodeExpression(tokens) { - public TokenIntLiteral Value = value; -} - -public sealed class NodeExpressionFloatLiteral(List tokens, TokenFloatLiteral value) : NodeExpression(tokens) -{ - public TokenFloatLiteral Value = value; + public readonly TokenIntLiteral Value = value; } public sealed class NodeExpressionStringLiteral(List tokens, TokenStringLiteral value) : NodeExpression(tokens) { - public TokenStringLiteral Value = value; + public readonly TokenStringLiteral Value = value; } public sealed class NodeExpressionBoolLiteral(List tokens, TokenBoolLiteral value) : NodeExpression(tokens) { - public TokenBoolLiteral Value = value; + public readonly TokenBoolLiteral Value = value; } public sealed class NodeExpressionIdent(List tokens, TokenIdent value) : NodeExpression(tokens) { - public TokenIdent Value = value; + public readonly TokenIdent Value = value; } public abstract class NodeType(List tokens) : Node(tokens); @@ -351,27 +328,27 @@ public sealed class NubTypeVoid(List tokens) : NodeType(tokens); public sealed class NodeTypeUInt(List tokens, int width) : NodeType(tokens) { - public int Width = width; + public readonly int Width = width; } public sealed class NodeTypeSInt(List tokens, int width) : NodeType(tokens) { - public int Width = width; + public readonly int Width = width; } public sealed class NodeTypeFloat(List tokens, int width) : NodeType(tokens) { - public int Width = width; + public readonly int Width = width; } public sealed class NodeTypeString(List tokens) : NodeType(tokens); public sealed class NodeTypeCustom(List tokens, TokenIdent name) : NodeType(tokens) { - public TokenIdent Name = name; + public readonly TokenIdent Name = name; } public sealed class NodeTypePointer(List tokens, NodeType to) : NodeType(tokens) { - public NodeType To = to; + public readonly NodeType To = to; } \ No newline at end of file diff --git a/compiler/Compiler/Tokenizer.cs b/compiler/Compiler/Tokenizer.cs index e809b55..4e1b8d3 100644 --- a/compiler/Compiler/Tokenizer.cs +++ b/compiler/Compiler/Tokenizer.cs @@ -342,7 +342,7 @@ public abstract class Token(int line, int column, int length) public sealed class TokenIdent(int line, int column, int length, string ident) : Token(line, column, length) { - public string Ident = ident; + public readonly string Ident = ident; } public sealed class TokenIntLiteral(int line, int column, int length, BigInteger value) : Token(line, column, length) @@ -350,19 +350,14 @@ public sealed class TokenIntLiteral(int line, int column, int length, BigInteger public BigInteger Value = value; } -public sealed class TokenFloatLiteral(int line, int column, int length, decimal value) : Token(line, column, length) -{ - public decimal Value = value; -} - public sealed class TokenStringLiteral(int line, int column, int length, string value) : Token(line, column, length) { - public string Value = value; + public readonly string Value = value; } public sealed class TokenBoolLiteral(int line, int column, int length, bool value) : Token(line, column, length) { - public bool Value = value; + public readonly bool Value = value; } public enum Symbol @@ -394,7 +389,7 @@ public enum Symbol public sealed class TokenSymbol(int line, int column, int length, Symbol symbol) : Token(line, column, length) { - public Symbol Symbol = symbol; + public readonly Symbol Symbol = symbol; } public enum Keyword @@ -406,5 +401,5 @@ public enum Keyword public sealed class TokenKeyword(int line, int column, int length, Keyword keyword) : Token(line, column, length) { - public Keyword Keyword = keyword; + public readonly Keyword Keyword = keyword; } \ No newline at end of file