...
This commit is contained in:
@@ -80,6 +80,18 @@ public sealed class Parser(List<Token> tokens)
|
||||
return new NodeStatementVariableDeclaration(TokensFrom(startIndex), name, type, value);
|
||||
}
|
||||
|
||||
if (TryExpectKeyword(Keyword.If))
|
||||
{
|
||||
var condition = ParseExpression();
|
||||
var thenBlock = ParseStatement();
|
||||
NodeStatement? elseBlock = null;
|
||||
|
||||
if (TryExpectKeyword(Keyword.Else))
|
||||
elseBlock = ParseStatement();
|
||||
|
||||
return new NodeStatementIf(TokensFrom(startIndex), condition, thenBlock, elseBlock);
|
||||
}
|
||||
|
||||
var target = ParseExpression();
|
||||
|
||||
if (TryExpectSymbol(Symbol.OpenParen))
|
||||
@@ -308,7 +320,7 @@ public sealed class Parser(List<Token> tokens)
|
||||
|
||||
public abstract class Node(List<Token> tokens)
|
||||
{
|
||||
public List<Token> Tokens = tokens;
|
||||
public readonly List<Token> Tokens = tokens;
|
||||
}
|
||||
|
||||
public abstract class NodeDefinition(List<Token> tokens) : Node(tokens);
|
||||
@@ -358,6 +370,13 @@ internal class NodeStatementAssignment(List<Token> tokens, NodeExpression target
|
||||
public readonly NodeExpression Value = value;
|
||||
}
|
||||
|
||||
internal class NodeStatementIf(List<Token> tokens, NodeExpression condition, NodeStatement thenBlock, NodeStatement? elseBlock) : NodeStatement(tokens)
|
||||
{
|
||||
public readonly NodeExpression Condition = condition;
|
||||
public readonly NodeStatement ThenBlock = thenBlock;
|
||||
public readonly NodeStatement? ElseBlock = elseBlock;
|
||||
}
|
||||
|
||||
public abstract class NodeExpression(List<Token> tokens) : Node(tokens);
|
||||
|
||||
public sealed class NodeExpressionIntLiteral(List<Token> tokens, TokenIntLiteral value) : NodeExpression(tokens)
|
||||
|
||||
Reference in New Issue
Block a user