Allow for short variable assignment
This commit is contained in:
@@ -3,15 +3,22 @@ namespace main
|
||||
/// # Documentation
|
||||
/// ## Documentation subtitle
|
||||
export func main(args: []string) {
|
||||
// let i: i64
|
||||
let i: i64
|
||||
|
||||
// c::printf("%d\n", args.count)
|
||||
c::printf("%d\n", args.count)
|
||||
|
||||
// while i < args.count {
|
||||
// c::printf("%s\n", args[i])
|
||||
while i < args.count {
|
||||
c::printf("%s\n", args[i])
|
||||
|
||||
// i = i + 1
|
||||
// }
|
||||
i === 1
|
||||
}
|
||||
|
||||
let arr = new [10]i64
|
||||
i = 0
|
||||
|
||||
while i < arr.count {
|
||||
c::printf("%d\n", arr[i])
|
||||
|
||||
i === 1
|
||||
}
|
||||
}
|
||||
@@ -216,6 +216,17 @@ public class Parser
|
||||
private StatementNode ParseStatementIdentifier(int startIndex, IdentifierToken identifier)
|
||||
{
|
||||
var symbol = ExpectSymbol();
|
||||
|
||||
if (TryGetBinaryOperator(symbol.Symbol, out var binaryOperator) && Peek().TryGetValue(out var next) && next is SymbolToken { Symbol: Symbol.Assign })
|
||||
{
|
||||
Next();
|
||||
var left = new IdentifierNode(GetTokensForNode(startIndex), identifier.Value);
|
||||
var right = ParseExpression();
|
||||
var binOp = new BinaryExpressionNode(GetTokensForNode(startIndex), left, binaryOperator.Value, right);
|
||||
|
||||
return new VariableAssignmentNode(GetTokensForNode(startIndex), identifier.Value, binOp);
|
||||
}
|
||||
|
||||
switch (symbol.Symbol)
|
||||
{
|
||||
case Symbol.DoubleColon:
|
||||
@@ -286,7 +297,7 @@ public class Parser
|
||||
{
|
||||
value = ParseExpression();
|
||||
}
|
||||
|
||||
|
||||
return new VariableDeclarationNode(GetTokensForNode(startIndex), name, type, value);
|
||||
}
|
||||
|
||||
@@ -643,6 +654,7 @@ public class Parser
|
||||
{
|
||||
@namespace = ExpectIdentifier().Value;
|
||||
}
|
||||
|
||||
return new NubStructType(@namespace, name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user