private void OpDoubleValue( Stack myStack, ETokens op, double d1, double d2) { switch (op) { case ETokens.BitwiseAnd: myStack.Push((double)((int)d2 & (int)d1)); break; case ETokens.BitwiseOr: myStack.Push((double)((int)d2 | (int)d1)); break; case ETokens.BitwiseXor: myStack.Push((double)((int)d2 ^ (int)d1)); break; case ETokens.Add: myStack.Push(d2 + d1); break; case ETokens.Subtract: myStack.Push(d2 - d1); break; case ETokens.Multiply: myStack.Push(d2 * d1); break; case ETokens.Divide: myStack.Push(d2 / d1); break; case ETokens.Mod: myStack.Push(d2 % d1); break; case ETokens.ShiftLeft: myStack.Push((double)((int)d2 << (int)d1)); break; case ETokens.ShiftRight: myStack.Push((double)((int)d2 >> (int)d1)); break; } }
private void OpStringValue(Stack myStack, ETokens op, string s1, string s2) { switch (op) { case ETokens.Add: myStack.Push(s2 + s1); break; default: throw new Exception("Invalid string operation."); } }
/// <summary> /// Handles function parameters /// </summary> private void ParameterList(MatchCollection mc, ETokens e) { int n = 0; if (_PfTokens[_PfTokens.Count - 1] == ETokens.User) { _PfTokens.Add(e); n++; } ETokens t = GetToken(mc); while (t != ETokens.RParen && t != ETokens.BadToken) { PutToken(t); int count = _PfTokens.Count; Expr(mc); if (_PfTokens.Count > count) n++; t = GetToken(mc); if (t != ETokens.Comma) break; t = GetToken(mc); } PutToken(t); _PfTokens.Add(ETokens.Function); _PfTokens.Add((ETokens) n); }
/// <summary> /// Saves the given token for future use /// </summary> /// <param name="t"></param> private void PutToken(ETokens t) { _PTokens[_PCount++] = t; }
/// <summary> /// Handles function parsing /// </summary> /// <param name="mc"></param> /// <param name="e"></param> /// <returns></returns> private bool Function(MatchCollection mc, ETokens e) { string s = _StringPool[(int)e].ToUpper(); ETokens t = GetFunction(mc, s); if (t != ETokens.BadToken) { _PfTokens.Add(t); t = GetToken(mc); if (t != ETokens.LParen) throw new Exception("Expecting left parenthesis."); ParameterList(mc, e); t = GetToken(mc); if (t != ETokens.RParen) throw new Exception("Expecting right parenthesis."); return (true); } return (false); }