package node.exprNode.prefixNode; import node.*; import node.exprNode.*; import node.exprNode.variableNode.*; import env.*; import type.*; import type.basicType.*; import runEnv.*; import runEnv.basicValue.*; public class PreIncNode extends PrefixVarNode { public PreIncNode( VariableNode right ) { super( right ); operator = "++"; } public Type checkType() { Type rightType = right.checkType(); if ( ! right.addressable() ) error( "Operand for ++ not addressable" ); if ( ! ( rightType instanceof IntType ) && ! ( rightType instanceof CharType ) ) error( "Operand of ++ operator must be an int or char" ); type = rightType; return type; } public RunValue eval( RunEnv runEnv ) { RunAddress rightData = right.evalAddress( runEnv ); RunValue rightValue = rightData.getValue(); if ( type instanceof IntType ) rightData.setValue( new IntValue( rightValue.intValue() + 1 ) ); else rightData.setValue( new CharValue( ( char ) ( rightValue.charValue() + 1 ) ) ); return rightData.getValue(); } }