...
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user