//------------------------------------------------------------ // extract the parameters protected override CTerm_Base Compile(ref string Term, Stack <CTerm_Base> Stack, CEnvironment Env) { _Terms = new List <CTerm_Base>(); int StackSize = Stack.Count; CTerm_Base Pending = GetNextTerm(ref Term, Stack, Env, Priotity); StackSize = Stack.Count - StackSize; if (StackSize == 1 && Stack.Peek().Type == TTermType.Bracket) { CTerm_Bracket Brackets = (CTerm_Bracket)Stack.Pop(); StackSize = Brackets.CopyTo(Stack); // Brackets = null; } if (StackSize != _TermCount) { string Msg = (StackSize < _TermCount) ? "missing operand(s)" : "too many operands"; Msg += " for " + _Name + "!"; throw new CTermException(Msg); } while (StackSize > 0) { _Terms.Add(Stack.Pop()); StackSize--; } return(Pending); }
//------------------------------------------------------------ // translate the Input string into the Term tree protected override CTerm_Base Compile(ref string Term, Stack <CTerm_Base> Stack, CEnvironment Env) { _TermA = null; _TermB = null; if (_bTermA || Stack.Count > 0) // take Term A, if it's needed or it's there anyway { if (Stack.Count < 1) { throw new CTermException(_Name + " missing 1st operand!"); } _TermA = Stack.Pop(); _bTermA = true; } ; CTerm_Base Result = GetNextTerm(ref Term, Stack, Env, Priotity); if (_bTermB) { if (Stack.Count < 1) { throw new CTermException(_Name + " missing 2nd operand!"); } _TermB = Stack.Pop(); } return(Result); }
protected override CTerm_Base Compile(ref string Term, System.Collections.Generic.Stack <CTerm_Base> Stack, CEnvironment Env) { _Term = null; int size = Stack.Count; CTerm_Base Pending = GetNextTerm(ref Term, Stack, Env, TPriority.separator); if (Stack.Count <= size) { throw new CTermException("a separator has to followed by an operand!"); } _Term = Stack.Pop(); return(Pending); }
//------------------------------------------------------------ // translate the Input string into the Term tree protected override CTerm_Base Compile(ref string Term, Stack <CTerm_Base> Stack, CEnvironment Env) { _Stack.Clear(); CTerm_Base Pending = GetNextTerm(ref Term, _Stack, Env, TPriority.end); if (_Stack.Count < 1) { throw new CTermException("missing operand in brackets!"); } if (Pending == null || Pending.Priotity != TPriority.end) { throw new CTermException("missing closing bracket!"); } return(null); }
//------------------------------------------------------------ protected override CTerm_Base Compile(ref string Term, Stack <CTerm_Base> Stack, CEnvironment Env) { _Term = null; if ((Stack.Count < 1) || (Stack.Peek().Type != TTermType.Variable)) { throw new CTermException(_Name + " needs a left-side operand!"); } _Variable = (CTerm_Variable)Stack.Pop(); int count = Stack.Count; CTerm_Base Pending = GetNextTerm(ref Term, Stack, Env, TPriority.end); if (Stack.Count <= count) { throw new CTermException(_Name + " needs a right-side operand!"); } _Term = Stack.Pop(); return(Pending); }
public CTerm_Mul(string Name, CTerm_Base TermA, CTerm_Base TermB) : base(Name, TPriority.ring, true, true) { _TermA = TermA; _TermB = TermB; }
protected bool _bTermB; // for compile: is TermB needed? (should be overwritten in the derived class) //------------------------------------------------------------ // standard constructor for 2Ops public CTerm_2Ops(string Name, TPriority Priority, bool TermA, bool TermB) : base(Name, Priority, TTermType.TwoOps) { _TermA = null; _bTermA = TermA; _TermB = null; _bTermB = TermB; }
//------------------------------------------------------------ public CTerm_Assignment(string Name) : base(Name, TPriority.function, TTermType.Assignment) { _Term = null; _Variable = null; }
public CTerm_Separator(string Name) : base(Name, TPriority.separator, TTermType.Seperator) { _Term = null; }