本文整理汇总了Java中org.spoofax.interpreter.core.Tools.isTermReal方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.isTermReal方法的具体用法?Java Tools.isTermReal怎么用?Java Tools.isTermReal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spoofax.interpreter.core.Tools
的用法示例。
在下文中一共展示了Tools.isTermReal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTermConstructor
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private IStrategoTerm getTermConstructor(IContext env, IStrategoTerm t) throws InterpreterException {
if (Tools.isTermInt(t) || Tools.isTermReal(t)) {
return t;
} else if (Tools.isTermString(t)) {
return env.getFactory().makeString("\"" + ((IStrategoString)t).stringValue() + "\"");
} else if (Tools.isTermAppl(t)) {
IStrategoAppl a = (IStrategoAppl)t;
if (Tools.isCons(a, env) || Tools.isNil(a, env))
return env.getFactory().makeAppl(env.getStrategoSignature().getNil());
else
return env.getFactory().makeString(((IStrategoAppl)t).getConstructor().getName());
} else if (Tools.isTermList(t)) {
return env.getFactory().makeList();
} else if (Tools.isTermTuple(t)) {
return env.getFactory().makeString("");
}
throw new InterpreterException("Unknown term '" + t + "'");
}
示例2: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
double a, b;
if(Tools.isTermReal(tvars[0])) {
a = ((IStrategoReal) tvars[0]).realValue();
} else if (Tools.isTermInt(tvars[0])) {
a = ((IStrategoInt) tvars[0]).intValue();
} else {
return false;
}
if(Tools.isTermReal(tvars[1])) {
b = ((IStrategoReal) tvars[1]).realValue();
} else if (Tools.isTermInt(tvars[1])) {
b = ((IStrategoInt) tvars[1]).intValue();
} else {
return false;
}
env.setCurrent(env.getFactory().makeReal(a + b));
return true;
}
示例3: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
double a, b;
// TODO: Factor out syntactic noise
// TODO: Apply this pattern to other primitives; many (all?) real operations also work on ints
if(Tools.isTermReal(tvars[0])) {
a = ((IStrategoReal) tvars[0]).realValue();
} else if (Tools.isTermInt(tvars[0])) {
a = ((IStrategoInt) tvars[0]).intValue();
} else {
return false;
}
if(Tools.isTermReal(tvars[1])) {
b = ((IStrategoReal) tvars[1]).realValue();
} else if (Tools.isTermInt(tvars[1])) {
b = ((IStrategoInt) tvars[1]).intValue();
} else {
return false;
}
env.setCurrent(env.getFactory().makeReal(a / b));
return true;
}
示例4: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] tvars) throws InterpreterException {
double a, b;
if(Tools.isTermReal(tvars[0])) {
a = ((IStrategoReal) tvars[0]).realValue();
} else if (Tools.isTermInt(tvars[0])) {
a = ((IStrategoInt) tvars[0]).intValue();
} else {
return false;
}
if(Tools.isTermReal(tvars[1])) {
b = ((IStrategoReal) tvars[1]).realValue();
} else if (Tools.isTermInt(tvars[1])) {
b = ((IStrategoInt) tvars[1]).intValue();
} else {
return false;
}
env.setCurrent(env.getFactory().makeReal(a * b));
return true;
}
示例5: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if (Tools.isTermInt(targs[0]))
return new SSL_int_to_string().call(env, sargs, targs);
if (!(Tools.isTermReal(targs[0])))
return false;
IStrategoReal a = (IStrategoReal) targs[0];
String s = String.format("%.17g", a.realValue());
env.setCurrent(env.getFactory().makeString(s));
return true;
}
示例6: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!Tools.isTermReal(targs[0]))
return false;
if(!Tools.isTermReal(targs[1]))
return false;
IStrategoReal a = (IStrategoReal) targs[0];
IStrategoReal b = (IStrategoReal) targs[1];
return a.realValue() > b.realValue();
}
示例7: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
if(Tools.isTermReal(tvars[0])) {
env.setCurrent(tvars[0]);
return true;
}
if(Tools.isTermInt(tvars[0])) {
IStrategoInt a = (IStrategoInt) tvars[0];
env.setCurrent(env.getFactory().makeReal(a.intValue()));
return true;
}
return false;
}
示例8: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
if(Tools.isTermInt(tvars[0])) {
env.setCurrent(tvars[0]);
return true;
}
if(Tools.isTermReal(tvars[0])) {
IStrategoReal a = (IStrategoReal) tvars[0];
env.setCurrent(env.getFactory().makeInt((int) a.realValue()));
return true;
}
return false;
}
示例9: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
if(!Tools.isTermReal(tvars[0]))
return false;
if(!Tools.isTermReal(tvars[1]))
return false;
IStrategoReal a = (IStrategoReal) tvars[0];
IStrategoReal b = (IStrategoReal) tvars[1];
env.setCurrent(env.getFactory().makeReal(a.realValue() - b.realValue()));
return true;
}
示例10: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!(Tools.isTermReal(targs[0])))
return false;
IStrategoReal a = (IStrategoReal) targs[0];
env.setCurrent(env.getFactory().makeReal(Math.sin(a.realValue())));
return true;
}
示例11: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!(Tools.isTermReal(targs[0])))
return false;
IStrategoReal a = (IStrategoReal) targs[0];
env.setCurrent(env.getFactory().makeReal(Math.cos(a.realValue())));
return true;
}
示例12: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!(Tools.isTermReal(targs[0])))
return false;
if(!(Tools.isTermInt(targs[1])))
return false;
IStrategoReal a = (IStrategoReal) targs[0];
IStrategoInt b = (IStrategoInt) targs[1];
String s = String.format("%." + b.intValue() + "f", a.realValue());
env.setCurrent(env.getFactory().makeString(s));
return true;
}
示例13: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!(Tools.isTermReal(targs[0])))
return false;
if(!(Tools.isTermReal(targs[1])))
return false;
IStrategoReal a = (IStrategoReal) targs[0];
IStrategoReal b = (IStrategoReal) targs[1];
env.setCurrent(env.getFactory().makeReal(a.realValue() % b.realValue()));
return true;
}
示例14: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!(Tools.isTermReal(targs[0])))
return false;
IStrategoReal a = (IStrategoReal) targs[0];
env.setCurrent(env.getFactory().makeReal(Math.sqrt(a.realValue())));
return true;
}
示例15: isSameTermType
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
public static boolean isSameTermType(IStrategoTerm t1, IStrategoTerm t2) {
return
(Tools.isTermAppl(t1) && Tools.isTermAppl(t2))
|| (Tools.isTermInt(t1) && Tools.isTermInt(t2))
|| (Tools.isTermList(t1) && Tools.isTermList(t2))
|| (Tools.isTermReal(t1) && Tools.isTermReal(t2))
|| (Tools.isTermString(t1) && Tools.isTermString(t2))
|| (Tools.isTermTuple(t1) && Tools.isTermTuple(t2));
}