public override TinyValue VisitCompExpression([NotNull] TinyUnityParser.CompExpressionContext context) { switch (context.op.Type) { case TinyUnityLexer.LT: return(lessThan(context)); case TinyUnityLexer.LTEquals: return(lessThanEq(context)); case TinyUnityLexer.GT: return(greaterThan(context)); case TinyUnityLexer.GTEquals: return(greaterThanEq(context)); default: throw new EvalException("unknown operator type: " + context.op.Type, context); } }
private TinyValue greaterThanEq(TinyUnityParser.CompExpressionContext context) { TinyValue lhs = this.Visit(context.expression(0)); TinyValue rhs = this.Visit(context.expression(1)); if (lhs == null || rhs == null) { throw new EvalException("Null operators: " + context.op.Type, context); } if (lhs.value is float && rhs.value is float) { return(new TinyValue((float)lhs.value >= (float)rhs.value)); } if (lhs.isString() && rhs.isString()) { return(new TinyValue(lhs.asString().CompareTo(rhs.asString()) >= 0)); } throw new EvalException("Bad operators: " + context.op.Type, context); }