Fix array access

This commit is contained in:
nub31
2025-01-30 18:47:25 +01:00
parent 9625c21148
commit a81d7939ba
8 changed files with 71 additions and 8 deletions

View File

@@ -13,6 +13,8 @@ public class Lexer
["if"] = Symbol.If,
["else"] = Symbol.Else,
["while"] = Symbol.While,
["break"] = Symbol.Break,
["continue"] = Symbol.Continue,
["return"] = Symbol.Return,
["new"] = Symbol.New,
};

View File

@@ -16,6 +16,8 @@ public enum Symbol
If,
Else,
While,
Break,
Continue,
Semicolon,
Colon,
OpenParen,

View File

@@ -0,0 +1,3 @@
namespace Nub.Lang.Frontend.Parsing;
public class BreakNode : StatementNode;

View File

@@ -0,0 +1,3 @@
namespace Nub.Lang.Frontend.Parsing;
public class ContinueNode : StatementNode;

View File

@@ -178,6 +178,8 @@ public class Parser
Symbol.Let => ParseVariableAssignment(),
Symbol.If => ParseIf(),
Symbol.While => ParseWhile(),
Symbol.Break => ParseBreak(),
Symbol.Continue => ParseContinue(),
_ => throw new Exception($"Unexpected symbol {symbol.Symbol}")
};
}
@@ -233,6 +235,18 @@ public class Parser
return new WhileNode(condition, body);
}
private BreakNode ParseBreak()
{
ExpectSymbol(Symbol.Semicolon);
return new BreakNode();
}
private ContinueNode ParseContinue()
{
ExpectSymbol(Symbol.Semicolon);
return new ContinueNode();
}
private ExpressionNode ParseExpression(int precedence = 0)
{
var left = ParsePrimaryExpression();

View File

@@ -86,6 +86,9 @@ public class ExpressionTyper
case ArrayIndexAssignmentNode arrayIndexAssignment:
PopulateArrayIndexAssignment(arrayIndexAssignment);
break;
case BreakNode:
case ContinueNode:
break;
case FuncCallStatementNode funcCall:
PopulateFuncCallStatement(funcCall);
break;