...
This commit is contained in:
@@ -80,14 +80,25 @@ public sealed class Parser(List<Token> tokens)
|
||||
return new NodeStatementVariableDeclaration(TokensFrom(startIndex), name, type, value);
|
||||
}
|
||||
|
||||
var expression = ParseExpression();
|
||||
var parameters = new List<NodeExpression>();
|
||||
var target = ParseExpression();
|
||||
|
||||
ExpectSymbol(Symbol.OpenParen);
|
||||
while (!TryExpectSymbol(Symbol.CloseParen))
|
||||
parameters.Add(ParseExpression());
|
||||
if (TryExpectSymbol(Symbol.OpenParen))
|
||||
{
|
||||
var parameters = new List<NodeExpression>();
|
||||
|
||||
return new NodeStatementFuncCall(TokensFrom(startIndex), expression, parameters);
|
||||
while (!TryExpectSymbol(Symbol.CloseParen))
|
||||
parameters.Add(ParseExpression());
|
||||
|
||||
return new NodeStatementFuncCall(TokensFrom(startIndex), target, parameters);
|
||||
}
|
||||
|
||||
if (TryExpectSymbol(Symbol.Equal))
|
||||
{
|
||||
var value = ParseExpression();
|
||||
return new NodeStatementAssignment(TokensFrom(startIndex), target, value);
|
||||
}
|
||||
|
||||
throw new Exception("Not a valid followup for expression statement");
|
||||
}
|
||||
|
||||
private NodeExpression ParseExpression()
|
||||
@@ -323,9 +334,9 @@ public sealed class NodeStatementBlock(List<Token> tokens, List<NodeStatement> s
|
||||
public readonly List<NodeStatement> Statements = statements;
|
||||
}
|
||||
|
||||
public sealed class NodeStatementFuncCall(List<Token> tokens, NodeExpression func, List<NodeExpression> parameters) : NodeStatement(tokens)
|
||||
public sealed class NodeStatementFuncCall(List<Token> tokens, NodeExpression target, List<NodeExpression> parameters) : NodeStatement(tokens)
|
||||
{
|
||||
public readonly NodeExpression Func = func;
|
||||
public readonly NodeExpression Target = target;
|
||||
public readonly List<NodeExpression> Parameters = parameters;
|
||||
}
|
||||
|
||||
@@ -341,6 +352,12 @@ internal class NodeStatementVariableDeclaration(List<Token> tokens, TokenIdent n
|
||||
public readonly NodeExpression Value = value;
|
||||
}
|
||||
|
||||
internal class NodeStatementAssignment(List<Token> tokens, NodeExpression target, NodeExpression value) : NodeStatement(tokens)
|
||||
{
|
||||
public readonly NodeExpression Target = target;
|
||||
public readonly NodeExpression Value = value;
|
||||
}
|
||||
|
||||
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