Exemple #1
0
        private void buttonProcess_Click(object sender, EventArgs e)
        {
            Lexema[] lex = Transliterator.Do(textIn.Text, true);

            // Clean up!
            textIn.Clear();
            foreach (object val in Lexema.GetValues(lex))
            {
                textIn.Text += val;
            }

            textOut.Clear();

            //System.Collections.Generic.
            ActionOnLexem[] stats =
            {
                do1,
                do2A,do2B,
                do3A,do3B, do3C,
                do4A,do4B,
                do5,
                do6A,do6B, do6C,
                do7,
                doError
            };

            #region transitions table initialization

            int[,] njuTab =
            {
/*(0) 1*/ { Array.IndexOf(stats, do2A),    Array.IndexOf(stats, doError), Array.IndexOf(stats, do7),     Array.IndexOf(stats, doError) },
/*(1) 2*/ { Array.IndexOf(stats, do2B),    Array.IndexOf(stats, do4A),    Array.IndexOf(stats, do3C),    Array.IndexOf(stats, doError) },
/*(2) 3*/ { Array.IndexOf(stats, do3A),    Array.IndexOf(stats, do4B),    Array.IndexOf(stats, doError), Array.IndexOf(stats, doError) },
/*(3) 4*/ { Array.IndexOf(stats, do6A),    Array.IndexOf(stats, doError), Array.IndexOf(stats, doError), Array.IndexOf(stats, do5)     },
/*(4) 5*/ { Array.IndexOf(stats, do6B),    Array.IndexOf(stats, doError), Array.IndexOf(stats, doError), Array.IndexOf(stats, doError) },
/*(5) 6*/ { Array.IndexOf(stats, do6C),    Array.IndexOf(stats, doError), Array.IndexOf(stats, doError), Array.IndexOf(stats, doError) },
/*(6) 7*/ { Array.IndexOf(stats, do3B),    Array.IndexOf(stats, doError), Array.IndexOf(stats, doError), Array.IndexOf(stats, doError) },
/*(7) e*/ { Array.IndexOf(stats, doError), Array.IndexOf(stats, doError), Array.IndexOf(stats, doError), Array.IndexOf(stats, doError) },
            };
            #endregion

            auto = new AutomatNumConst(
                // A
                new object[] {
                new Lexema(Transliterator.KindOfSymbol.Digit, null),
                new Lexema(Transliterator.KindOfSymbol.E, null),
                new Lexema(Transliterator.KindOfSymbol.Dot, null),
                new Lexema(Transliterator.KindOfSymbol.Sign, null)
            },
                // Z
                new string[] { "error", "int", "float", "real" },
                // S
                stats,
                // nju
                njuTab,
                // zeta
                new int[] { 0, 1, 2, 0, 0, 3, 0, 0 }
                );

            object[] whatsDone;
            object[] outsSequence;
            object   constant             = null;
            string   formalRepresentation = "";

            StepCount = 1;
            dataGridView1.Rows.Clear();

            auto.Step      += new TerminalStepDelegate(auto_Step);
            auto.StateIndex = 0;
            auto.Process(lex, out whatsDone, out outsSequence);

            if (outsSequence.Length < 1)
            {
                MessageBox.Show("Empty constant", "Failed",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            switch (outsSequence[outsSequence.Length - 1] as string)
            {
            case "int":
                constant             = auto.Ч;
                formalRepresentation = auto.Ч.ToString();
                break;

            case "float":
                auto.П               = -auto.С;
                constant             = auto.Ч * Math.Pow(10, auto.П);
                formalRepresentation =
                    String.Format("{0}*10^{1}", auto.Ч, auto.П);
                break;

            case "real":
                auto.П              *= auto.З;
                auto.П              -= auto.С;
                constant             = auto.Ч * (Math.Pow(10, auto.П));
                formalRepresentation =
                    String.Format("{0}*10^{1}", auto.Ч, auto.П);
                break;

            default:
                MessageBox.Show("Cannot parse constant", "Failed",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            textOut.Text = String.Format("{0} (={1}).",
                                         formalRepresentation, constant.ToString()
                                         );
        }