Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* #%L
* Parsington: the SciJava mathematical expression parser.
* %%
* Copyright (C) 2015 - 2019 Board of Regents of the University of
* Wisconsin-Madison.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.parse.eval;
import java.util.Deque;
import org.scijava.parse.ExpressionParser;
import org.scijava.parse.Function;
import org.scijava.parse.Operator;
import org.scijava.parse.Operators;
import org.scijava.parse.Tokens;
import org.scijava.parse.Variable;
/**
* Base class for stack-based evaluators which support the standard operators.
*
* @author Curtis Rueden
*/
public abstract class AbstractStandardStackEvaluator extends
AbstractStackEvaluator implements StandardEvaluator
{
public AbstractStandardStackEvaluator() {
super();
}
public AbstractStandardStackEvaluator(final ExpressionParser parser) {
super(parser);
}
// -- StandardEvaluator methods --
// -- postfix --
@Override
public Object postInc(final Object a) {
final Variable v = var(a);
final Object value = value(v);
if (value == null) return null;
set(v, add(a, 1));
return value;
}
@Override
public Object postDec(final Object a) {
final Variable v = var(a);
final Object value = value(v);
if (value == null) return null;
set(v, sub(a, 1));
return value;
}
// -- unary --
@Override
public Object preInc(final Object a) {
final Variable v = var(a);
final Object result = add(a, 1);
set(v, result);
return result;
}
@Override
public Object preDec(final Object a) {
final Variable v = var(a);
final Object result = sub(a, 1);
set(v, result);
return result;
}
// -- assignment --
@Override
public Object assign(final Object a, final Object b) {
final Variable v = var(a);
set(v, value(b));
return v;
}
@Override
public Object powAssign(final Object a, final Object b) {
return assign(a, pow(a, b));
}
@Override
public Object dotPowAssign(final Object a, final Object b) {
return assign(a, dotPow(a, b));
}
@Override
public Object mulAssign(final Object a, final Object b) {
return assign(a, mul(a, b));
}
@Override
public Object divAssign(final Object a, final Object b) {
return assign(a, div(a, b));
}
@Override
public Object modAssign(final Object a, final Object b) {
return assign(a, mod(a, b));
}
@Override
public Object rightDivAssign(final Object a, final Object b) {
return assign(a, rightDiv(a, b));
}
@Override
public Object dotDivAssign(final Object a, final Object b) {
return assign(a, dotDiv(a, b));
}
@Override
public Object dotRightDivAssign(final Object a, final Object b) {
return assign(a, dotRightDiv(a, b));
}
@Override
public Object addAssign(final Object a, final Object b) {
return assign(a, add(a, b));
}
@Override
public Object subAssign(final Object a, final Object b) {
return assign(a, sub(a, b));
}
@Override
public Object andAssign(final Object a, final Object b) {
return assign(a, bitwiseAnd(a, b));
}
@Override
public Object orAssign(final Object a, final Object b) {
return assign(a, bitwiseOr(a, b));
}
@Override
public Object leftShiftAssign(final Object a, final Object b) {
return assign(a, leftShift(a, b));
}
@Override
public Object rightShiftAssign(final Object a, final Object b) {
return assign(a, rightShift(a, b));
}
@Override
public Object unsignedRightShiftAssign(final Object a, final Object b) {
return assign(a, unsignedRightShift(a, b));
}
// -- StackEvaluator methods --
@Override
public Object execute(final Operator op, final Deque