Fix array access
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -16,6 +16,8 @@ public enum Symbol
|
||||
If,
|
||||
Else,
|
||||
While,
|
||||
Break,
|
||||
Continue,
|
||||
Semicolon,
|
||||
Colon,
|
||||
OpenParen,
|
||||
|
||||
3
Nub.Lang/Nub.Lang/Frontend/Parsing/BreakNode.cs
Normal file
3
Nub.Lang/Nub.Lang/Frontend/Parsing/BreakNode.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace Nub.Lang.Frontend.Parsing;
|
||||
|
||||
public class BreakNode : StatementNode;
|
||||
3
Nub.Lang/Nub.Lang/Frontend/Parsing/ContinueNode.cs
Normal file
3
Nub.Lang/Nub.Lang/Frontend/Parsing/ContinueNode.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace Nub.Lang.Frontend.Parsing;
|
||||
|
||||
public class ContinueNode : StatementNode;
|
||||
@@ -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();
|
||||
|
||||
@@ -86,6 +86,9 @@ public class ExpressionTyper
|
||||
case ArrayIndexAssignmentNode arrayIndexAssignment:
|
||||
PopulateArrayIndexAssignment(arrayIndexAssignment);
|
||||
break;
|
||||
case BreakNode:
|
||||
case ContinueNode:
|
||||
break;
|
||||
case FuncCallStatementNode funcCall:
|
||||
PopulateFuncCallStatement(funcCall);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user