public override complexVariableClass complexVariable(complexVariableClass context) { var scope = scopeChain(context.chain, context._this == null? indexed : indexed.Parent); if (context._this != null && scope == null && indexed.Parent != null) { scope = indexed.Parent; } BaseAHKNode retVal = null; switch (context.variable) { case variableClass o: o.extraInfo = scope; retVal = variable(o); break; case dotUnwrapClass o: o.variableOrFunction.extraInfo = scope; retVal = variable((variableClass)o.variableOrFunction); break; } if (retVal == null) { return(null); } context.extraInfo = retVal.extraInfo; return(context); }
object PostfixEvaluator(List <BaseAHKNode> postfixList) { var stack = new Stack <BaseAHKNode>(); foreach (var node in postfixList) { switch (node) { case opClass o: if (stack.Count < 2) { } //error var item2 = stack.Pop(); var item1 = stack.Pop(); var retItem = new BaseAHKNode() { extraInfo = binaryOpEvaluator(item1, item2, o) }; stack.Push(retItem); break; default: stack.Push(node); break; } } if (stack.Count != 1) { } //error return(stack.Pop().extraInfo); }
bool isTrue(BaseAHKNode node) { switch (node) { case INTClass o: return(o.INT != 0); case DOUBLEClass o: return(true); case HEXClass o: return(true); case complexVariableClass o: if (o.extraInfo is VariableValue v) { return(isTrue(v.Value)); } return(false); case binaryOperationClass o: return(isTrue(o.extraInfo)); default: return(isTrue(node.extraInfo)); } }
public override complexFunctionCallClass complexFunctionCall(complexFunctionCallClass context) { var scope = scopeChain(context.chain, context._this == null? indexed : indexed.Parent); // in case of this.function() in a class method if (context._this != null && scope == null && indexed.Parent != null) { scope = indexed.Parent; } BaseAHKNode retVal = null; switch (context.function) { case functionCallClass o: o.extraInfo = scope; retVal = functionCall(o); break; case dotUnwrapClass o: o.variableOrFunction.extraInfo = scope; retVal = functionCall((functionCallClass)o.variableOrFunction); break; } if (retVal == null) { return(null); } // context.extraInfo = retVal is VariableValue v? v.Value : retVal.extraInfo; context.extraInfo = retVal.extraInfo; return(context); }
public override BaseAHKNode othersFilter(BaseAHKNode context) { if (context is directiveClass d) { if (d.directiveName.ToLower() == "include") { LoadAssembly(d.directiveParam); } else if (d.directiveName.ToLower() == "using") { LoadNestedTypesAndMethods(d.directiveParam); } } return(context); }
public override newObjectClass newObject(newObjectClass context) { List <BaseAHKNode> parameterList = null; switch (context.className) { case functionCallClass o: parameterList = o.functionParameterList; break; case dotUnwrapClass o: parameterList = ((functionCallClass)o.variableOrFunction).functionParameterList; break; } for (int i = 0; i < parameterList.Count; i++) { parameterList[i] = traverser.objectDispatcher(parameterList[i]); } var scope = scopeChain(context.chain, indexed); BaseAHKNode retVal = null; switch (context.className) { case functionCallClass o: o.extraInfo = scope; retVal = createNewInstance(o); break; case dotUnwrapClass o: o.variableOrFunction.extraInfo = scope; retVal = createNewInstance((functionCallClass)o.variableOrFunction); break; } if (retVal == null) { return(null); } // var retVal = scopeAndVariableOrFunction(context); context.extraInfo = retVal is VariableValue v? v.Value : retVal.extraInfo; return(context); }
object binaryOpEvaluator(BaseAHKNode item1, BaseAHKNode item2, opClass op) { var item1EI = item1.extraInfo is VariableValue v1? v1.Value : item1.extraInfo; var item2EI = item2.extraInfo is VariableValue v2? v2.Value : item2.extraInfo; item1EI = item1EI is bool?(bool)item1EI == true? 1 : 0 : item1EI; item2EI = item2EI is bool?(bool)item2EI == true? 1 : 0 : item2EI; switch (op.op) { case "+": return((dynamic)item1EI + (dynamic)item2EI); case "-": return((dynamic)item1EI - (dynamic)item2EI); case "*": return((dynamic)item1EI * (dynamic)item2EI); case "/": return(Convert.ToDouble(item1EI) / Convert.ToDouble(item2EI)); case "//": return((Int64)((dynamic)item1EI / (dynamic)item2EI)); case "**": return(MathF.Pow((dynamic)item1EI, (dynamic)item2EI)); case "<<": return((dynamic)item1EI << Convert.ToInt32(item2EI)); case ">>": return((dynamic)item1EI >> Convert.ToInt32(item2EI)); case "&": return((dynamic)item1EI & (dynamic)item2EI); case "|": return((dynamic)item1EI | (dynamic)item2EI); case "^": return((dynamic)item1EI ^ (dynamic)item2EI); case ".": return(item1EI.ToString() + item2EI.ToString()); case "<": return((dynamic)item1EI < (dynamic)item2EI); case ">": return((dynamic)item1EI > (dynamic)item2EI); case "=": return(item1EI.ToString().ToLower() == item2EI.ToString().ToLower()); case "<=": return((dynamic)item1EI <= (dynamic)item2EI); case ">=": return((dynamic)item1EI >= (dynamic)item2EI); case "==": return(item1EI.ToString() == item2EI.ToString()); case "!=": return(item1EI.ToString() != item2EI.ToString()); case "&&": return(isTrue(item1) && isTrue(item2)); case "||": return(isTrue(item1) || isTrue(item2)); } return(null); }