public Operador(TextoAParsear t) { operando = ' '; try { if (t.Vacio()) { throw new NotValidObject(); } char c = t.GetChar(); switch (c) { case '+': case '-': case '/': case '*': operando = c; t.CharProcessed(); return; } throw new NotValidObject(); } catch (EndOfString eos) { throw new NotValidObject(); } }
private void run_Click(object sender, EventArgs e) { string ope = operacion.Text; if (ope == "clean") { log.Text = ""; operacion.Text = ""; VarValue.lista.Clear(); listaVariables.Text = ""; return; } log.Text += ope + " = "; string result; try { TextoAParsear tmp = new TextoAParsear(ope); Operacion op = new Operacion(tmp); if (!tmp.Vacio()) { throw new Exception("Error de sintaxis"); } result = op.Evalua().ToString(); log.Text += result + "\r\n"; log.SelectionStart = log.Text.Length; log.SelectionLength = 0; log.ScrollToCaret(); log.SelectAll(); operacion.Text = "(" + result + ")"; operacion.SelectionStart = operacion.Text.Length; operacion.SelectionLength = 0; listaVariables.Clear(); foreach (VarValue val in VarValue.lista) { listaVariables.Text += val.nombre.ToString() + ": " + val.value.ToString() + "\r\n"; } } catch (Exception ex) { log.Text += "\r\n" + ex.Message + "\r\n\r\n"; } operacion.Focus(); }
public OperadorVariable(TextoAParsear t) { if (t.Vacio()) { throw new NotValidObject(); } char c = t.GetChar(); if (c == '=') { isAssignment = true; op = null; t.CharProcessed(); } else { op = new Operador(t); } }