Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void ProcessPostfix(Control ctl)
- {
- if (ExprHelper.IsOperator(ctl.Text))
- {
- if (_preCtl != null && ExprHelper.IsOperator(_preCtl.Text))
- {
- if (ctl.Text == "-")
- {
- _nextCtl.Text = ctl.Text _nextCtl.Text;
- Output(_nextCtl);
- }
- else if (ExprHelper.IsUnaryFunction(ctl.Text))
- {
- PushStack(ctl);
- }
- }
- else
- {
- while (pnlStack.Controls.Count > 0 &&
- ExprHelper.GetPriority(ctl.Text) <= ExprHelper.GetPriority(PeekStack().Text))
- Output(PopStack());
- PushStack(ctl);
- }
- }
- else if (ctl.Text == "(")
- PushStack(ctl);
- else if (ctl.Text == ")")
- {
- Control x = PopStack();
- while (x.Text != "(")
- {
- Output(x);
- x = PopStack();
- }
- }
- else // IsOperand
- {
- Output(ctl);
- }
- }
- Control PeekStack()
- {
- return pnlStack.Controls[pnlStack.Controls.Count - 1];
- }
- Control PopStack()
- {
- Control ctl = pnlStack.Controls[pnlStack.Controls.Count - 1];
- pnlStack.Controls.Remove(ctl);
- return ctl;
- }
- void PushStack(Control ctl)
- {
- pnlStack.Controls.Add(ctl);
- if (pnlStack.Controls.Count > 1)
- pnlStack.Controls[pnlStack.Controls.Count - 2].BackgroundImage = _imgNormal;
- }
- void Output(Control ctl)
- {
- pnlOutput.Controls.Add(ctl);
- if (pnlOutput.Controls.Count > 1)
- pnlOutput.Controls[pnlOutput.Controls.Count - 2].BackgroundImage = _imgNormal;
- }
Advertisement
Add Comment
Please, Sign In to add comment