Пример #1
0
        public ListAccess ParseListAccess(Token token)
        {
            Token identifier = token;

            this.Consume(TokenType.LEFT_SQUARE_BRACKET);
            Token indexer = lexer.Next();
            AST   index   = null;

            if (indexer.Is(TokenType.IDENTIFIER))
            {
                index = new Tree.Variable(indexer.Value);
            }
            else if (indexer.Is(TokenType.NUMBER))
            {
                index = new Tree.Number(indexer.Value);
            }
            else if (lexer.Peek().isOperator())
            {
                index = this.Expression(indexer);
            }
            else
            {
                this.Error("List accesser not allowed. ", indexer);
            }
            this.Consume(TokenType.RIGHT_SQUARE_BRACKET);
            return(new ListAccess(identifier.Value, index));
        }
Пример #2
0
        public AST ParseListReAssignment(Token token)
        {
            this.Consume(TokenType.LEFT_SQUARE_BRACKET);
            Token index = lexer.Next();

            this.Consume(TokenType.RIGHT_SQUARE_BRACKET);
            AST indexer = null;

            if (index.Is(TokenType.IDENTIFIER))
            {
                indexer = new Tree.Variable(index.Value);
            }
            else if (index.Is(TokenType.NUMBER))
            {
                indexer = new Tree.Number(index.Value);
            }
            else
            {
                this.Error("Only variables or numbers can be used to access list items", index);
            }
            AST right = null;

            if (lexer.Peek().Is(TokenType.IS))
            {
                //there is the right part;
                this.Consume(TokenType.IS);
                right = this.Assignee();
            }
            else if (lexer.Peek().Is(TokenType.SEMI_COLON))
            {
                right = new Tree.Null();
            }
            ListModify modifier = new ListModify(token.Value, indexer, right);

            return(new ReAssignment(token.Value, modifier));
        }