This commit is contained in:
2026-02-08 20:26:11 +01:00
parent 6f03e2203f
commit b31a2d01c6
3 changed files with 50 additions and 15 deletions

View File

@@ -208,6 +208,16 @@ public sealed class Parser(string fileName, List<Token> tokens)
ExpectSymbol(Symbol.CloseParen);
expr = value;
}
else if (TryExpectSymbol(Symbol.Minus))
{
var target = ParseExpression();
expr = new NodeExpressionUnary(TokensFrom(startIndex), target, NodeExpressionUnary.Op.Negate);
}
else if (TryExpectSymbol(Symbol.Bang))
{
var target = ParseExpression();
expr = new NodeExpressionUnary(TokensFrom(startIndex), target, NodeExpressionUnary.Op.Invert);
}
else if (TryExpectIntLiteral(out var intLiteral))
{
expr = new NodeExpressionIntLiteral(TokensFrom(startIndex), intLiteral);
@@ -617,7 +627,6 @@ public sealed class NodeExpressionBinary(List<Token> tokens, NodeExpression left
public readonly Op Operation = operation;
public readonly NodeExpression Right = right;
public enum Op
{
Add,
@@ -645,6 +654,18 @@ public sealed class NodeExpressionBinary(List<Token> tokens, NodeExpression left
}
}
public sealed class NodeExpressionUnary(List<Token> tokens, NodeExpression target, NodeExpressionUnary.Op op) : NodeExpression(tokens)
{
public NodeExpression Target { get; } = target;
public Op Operation { get; } = op;
public enum Op
{
Negate,
Invert,
}
}
public abstract class NodeType(List<Token> tokens) : Node(tokens);
public sealed class NodeTypeVoid(List<Token> tokens) : NodeType(tokens);