コード例 #1
0
        private Expr Postfix()
        {
            Expr expression = Primary();

            while (Match(TokenType.MinusMinus, TokenType.PlusPlus))
            {
                expression = new Expr.Postfix(Previous(), expression);
            }
            return(expression);
        }
コード例 #2
0
ファイル: Interpreter.cs プロジェクト: tstavrianos/LoxSharp
        public object Visit(Expr.Postfix postfix)
        {
            object right = Evaluate(postfix.lhs);

            ValidateNumberOperand(postfix.opp, right);
            switch (postfix.opp.type)
            {
            case TokenType.MinusMinus:
                right = (double)right - 1;
                break;

            case TokenType.PlusPlus:
                right = (double)right + 1;
                break;
            }
            /// This was made up by me because in the book there is nothing that assigns this value.
            // Cast to variable type
            Expr.Variable asVariable = (Expr.Variable)postfix.lhs;
            // Assign it's value
            m_Enviroment.Assign(asVariable.name, right);
            // Return the value.
            return(right);
        }
コード例 #3
0
 public object Visit(Expr.Postfix _postfix)
 {
     return(null);
 }
コード例 #4
0
 string Expr.IVisitor <string> .Visit(Expr.Postfix postfix)
 {
     return(Parenthesize(postfix.opp.lexeme, postfix.lhs));
 }