com.obdobion.algebrain.operator.OpNor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algebrain Show documentation
Show all versions of algebrain Show documentation
Equation processing for Java
The newest version!
package com.obdobion.algebrain.operator;
import java.text.ParseException;
import com.obdobion.algebrain.EquPart;
import com.obdobion.algebrain.Operator;
import com.obdobion.algebrain.ValueStack;
/**
*
* OpOr class.
*
*
* @author Chris DeGreef [email protected]
* @since 1.3.9
*/
public class OpNor extends Operator
{
/**
*
* Constructor for OpOr.
*
*/
public OpNor()
{}
/**
*
* Constructor for OpOr.
*
*
* @param opTok a {@link com.obdobion.algebrain.EquPart} object.
*/
public OpNor(final EquPart opTok)
{
super(opTok);
}
/** {@inheritDoc} */
@Override
protected int precedence()
{
return 9;
}
/** {@inheritDoc} */
@Override
public void resolve(final ValueStack values) throws Exception
{
if (values.size() < 2)
throw new Exception("missing operands for " + toString());
try
{
final boolean b0 = values.popBoolean();
final boolean b1 = values.popBoolean();
values.push(new Boolean(!(b1 || b0)));
} catch (final ParseException e)
{
e.fillInStackTrace();
throw new Exception(toString() + "; " + e.getMessage(), e);
}
}
/** {@inheritDoc} */
@Override
public String toString()
{
return "op(nor)";
}
}