예제 #1
0
        public LetStatement ParseLetStatement()
        {
            var statement = new LetStatement();

            statement.Token = this.CurrentToken;

            if (!this.ExpectPeek(TokenType.IDENT))
            {
                return(null);
            }

            statement.Name = new Identifier(this.CurrentToken, this.CurrentToken.Literal);

            if (!this.ExpectPeek(TokenType.ASSIGN))
            {
                return(null);
            }

            while (this.CurrentToken.Type != TokenType.SEMICOLON)
            {
                this.ReadToken();
            }

            return(statement);
        }
예제 #2
0
파일: Parser.cs 프로젝트: strider-/Monkey
        private LetStatement ParseAssignmentOperatorStatement()
        {
            var statement = new LetStatement(new Token(Token.Let, "let"));
            var ident     = new Identifier(_current)
            {
                Value = _current.Literal
            };

            statement.Name  = ident;
            statement.Value = AssignmentOperatorInfixExpression(ident);

            if (PeekTokenIs(Token.Semicolon))
            {
                NextToken();
            }

            return(statement);
        }
예제 #3
0
파일: Parser.cs 프로젝트: strider-/Monkey
        private LetStatement ParseLetStatement()
        {
            var statement = new LetStatement(_current);

            if (!ExpectPeek(Token.Ident))
            {
                return(null);
            }

            statement.Name = new Identifier(_current)
            {
                Value = _current.Literal
            };

            if (PeekTokenIsAssignmentOperator())
            {
                statement.Value = AssignmentOperatorInfixExpression(statement.Name);
            }
            else
            {
                if (!ExpectPeek(Token.Assign))
                {
                    return(null);
                }

                NextToken();

                statement.Value = ParseExpression(Lowest);
            }

            if (PeekTokenIs(Token.Semicolon))
            {
                NextToken();
            }

            return(statement);
        }