protected override bool Visit(ASTIndexing node) { if (!Visit(node.Child)) { return(false); } if (!Visit(node.Arguments)) { return(false); } var childType = node.Child.TypeInfo; if (!(childType is ArrayType a)) { Error(node.Position, $"Can't index none array {childType}, yet"); return(false); } var count = node.Arguments.Count(); if (count != 1) { Error(node.Position, $"Can't index none array {childType}, yet"); return(false); } var first = node.Arguments.First(); if (!(first.TypeInfo is IntegerType)) { Error(node.Position, "Can't index array with a none Interger value"); return(false); } node.TypeInfo = a.ItemType; return(true); }
protected override bool Visit(ASTIndexing node) { throw new NotImplementedException(); }
private ASTNode ParseUnary() { ASTUnary topPrefix = null, leafPrefix = null; for (;;) { ASTUnary res; if (EatToken(TokenKind.ExclamationMark)) { res = new ASTNot(EatenToken.Position); } else if (EatToken(TokenKind.KeywordNew)) { res = new ASTNew(EatenToken.Position); } else { break; } if (topPrefix == null) { topPrefix = res; leafPrefix = res; } else { leafPrefix.Child = res; leafPrefix = res; } } var result = ParseTerm(); if (result == null) { return(null); } ASTUnary topPostfix = null, leafPostfix = null; for (;;) { ASTUnary res; if (EatToken(TokenKind.SquareLeft)) { var expr = ParseExpression(); if (expr == null) { return(null); } if (!EatExpect(TokenKind.SquareRight)) { return(null); } res = new ASTIndexing(PeekToken().Position) { Value = expr }; } else if (EatToken(TokenKind.ParenthesesLeft)) { var start = EatenToken; var arguments = new List <ASTNode>(); while (!EatToken(TokenKind.ParenthesesRight)) { if (arguments.Count != 0 && !EatExpect(TokenKind.Comma)) { return(null); } var argument = ParseExpression(); if (argument == null) { return(null); } arguments.Add(argument); } res = new ASTCall(start.Position) { Arguments = arguments }; } else { break; } if (topPostfix == null) { leafPostfix = res; topPostfix = res; } else { res.Child = topPostfix; topPostfix = res; } } if (leafPostfix != null) { leafPostfix.Child = result; result = topPostfix; } if (leafPrefix != null) { leafPrefix.Child = result; result = topPrefix; } return(result); }
public bool Visit(ASTIndexing node) { throw new NotImplementedException(); }
protected abstract bool Visit(ASTIndexing node);