public static LinkedListNode <Lexeme> TryParse(LinkedListNode <Lexeme> lexemes, out Var resultNode) { resultNode = null; if (lexemes.Value.Type != LT.IDENT) { return(lexemes); } resultNode = new Var { Token = lexemes.Value }; var nextLexeme = lexemes.Next; if (nextLexeme.Value.Type == LT.OP_SQBRACKET_O) { nextLexeme = nextLexeme.Next; nextLexeme = BinaryExpr.TryParseExpr(nextLexeme, out var expr); if (expr == null) { throw new Exception($"Opening square bracket found, but no array index at {nextLexeme.Value.File}:{nextLexeme.Value.Line}"); } if (nextLexeme.Value.Type != LT.OP_SQBRACKET_C) { throw new Exception($"Missing closing square bracket after array index at {nextLexeme.Value.File}:{nextLexeme.Value.Line}"); } resultNode = new ArrayVar { Token = lexemes.Value, Index = expr }; return(nextLexeme.Next); } return(nextLexeme); }