Пример #1
0
 private void OKButton_Click(object sender, EventArgs e)
 {
     GrammarProvider.GetGrammar().StartSymbol  = startSymbolTextBox.Text[0];
     GrammarProvider.GetGrammar().Nonterminals = Helper.StringToCharList(nonterminalsTextBox.Text);
     GrammarProvider.GetGrammar().Terminals    = Helper.StringToCharList(terminalsTextBox.Text);
     Close();
 }
Пример #2
0
        private void editButton_Click(object sender, EventArgs e)
        {
            var t = new EditGrammarForm();

            t.ShowDialog();
            grammarInfoWebBrowser.DocumentText = GrammarProvider.GetGrammar().GrammarInfoAsHTML();
        }
Пример #3
0
 private void terminalsTextBox_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (!GrammarProvider.GetGrammar().IsValidTerminal(e.KeyChar) && !char.IsControl(e.KeyChar))
     {
         e.Handled = true;
     }
 }
Пример #4
0
 private void saveAsButton_Click(object sender, EventArgs e)
 {
     if (grammarSaveFileDialog.ShowDialog() == DialogResult.OK)
     {
         GrammarProvider.GetGrammar().SaveToJson(grammarSaveFileDialog.FileName);
     }
 }
Пример #5
0
 private void AddNewProductionButton_Click(object sender, EventArgs e)
 {
     GrammarProvider.GetGrammar().ProductionList.Add(new Production {
         Left = 'S', Right = "@"
     });
     productionsDataGridView.DataSource = null;
     productionsDataGridView.DataSource = GrammarProvider.GetGrammar().ProductionList;
 }
        private void editButton_Click(object sender, EventArgs e)
        {
            var t = new GrammarEditorForm();

            t.ShowDialog();
            //GrammarProvider.GetGrammar().LoadFromFile(Properties.Resources.DefaultGrammarLocation);
            grammarInfoWebBrowser.DocumentText = GrammarProvider.GetGrammar().GrammarInfoAsHTML();
        }
 private void OKButton_Click(object sender, EventArgs e)
 {
     GrammarProvider.GetGrammar().Terminals    = Helper.LowerAndSymbolsLetters(terminalsTextBox.Text);
     GrammarProvider.GetGrammar().Nonterminals = Helper.UpperLetters(nonterminalsTextBox.Text);
     GrammarProvider.GetGrammar().StartSymbol  = startSymbolTextBox.Text[0];
     //GrammarProvider.GetGrammar().SaveToJson(Properties.Resources.DefaultGrammarLocation);
     Close();
 }
Пример #8
0
 public EditGrammarForm()
 {
     InitializeComponent();
     startSymbolTextBox.Text            = GrammarProvider.GetGrammar().StartSymbol.ToString();
     terminalsTextBox.Text              = Helper.CharListToString(GrammarProvider.GetGrammar().Terminals);
     nonterminalsTextBox.Text           = Helper.CharListToString(GrammarProvider.GetGrammar().Nonterminals);
     productionsDataGridView.DataSource = GrammarProvider.GetGrammar().ProductionList;
     productionsDataGridView.AutoResizeColumns();
 }
Пример #9
0
        private void noLambdaProductionsButton_Click(object sender, EventArgs e)
        {
            Grammar g = GrammarAlgorithms.EliminateLambdaProductions(GrammarProvider.GetGrammar());

            grammarInfoWebBrowser.DocumentText = g.GrammarInfoAsHTML();
            if (grammarSaveFileDialog.ShowDialog() == DialogResult.OK)
            {
                g.SaveToJson(grammarSaveFileDialog.FileName);
            }
        }
        private void GrammarEditorForm_Load(object sender, EventArgs e)
        {
            //g.LoadFromFile(Properties.Resources.DefaultGrammarLocation);


            startSymbolTextBox.Text  = GrammarProvider.GetGrammar().StartSymbol.ToString();
            terminalsTextBox.Text    = Helper.CharListToString(GrammarProvider.GetGrammar().Terminals);
            nonterminalsTextBox.Text = Helper.CharListToString(GrammarProvider.GetGrammar().Nonterminals);

            productionsDataGridView.DataSource = GrammarProvider.GetGrammar().ProductionList;
        }
Пример #11
0
        private void productionsDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            Production p = new Production();

            p.Left  = productionsDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString()[0];
            p.Right = productionsDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
            if (!GrammarProvider.GetGrammar().IsValidProduction(p))
            {
                MessageBox.Show("!");
            }
        }
Пример #12
0
 private void grammarInfoForm_Load(object sender, EventArgs e)
 {
     try
     {
         GrammarProvider.GetGrammar().LoadFromFile(Properties.Resources.DefaultGrammarLocation);
         grammarInfoWebBrowser.DocumentText = GrammarProvider.GetGrammar().GrammarInfoAsHTML();
     }
     catch (Exception)
     {
         GrammarProvider.GetGrammar().Parse(inputTextBox.Text);
         grammarInfoWebBrowser.DocumentText = GrammarProvider.GetGrammar().GrammarInfoAsText();
     }
 }
Пример #13
0
        private void startSymbolTextBox_Leave(object sender, EventArgs e)
        {
            char startSymbol = startSymbolTextBox.Text[0];

            if (startSymbolTextBox.Text.Length > 1)
            {
                MessageBox.Show("!");
            }
            if (GrammarProvider.GetGrammar().IsValidStartSymbol(startSymbol))
            {
                GrammarProvider.GetGrammar().StartSymbol = startSymbol;
            }
            else
            {
                MessageBox.Show("!");
            }
        }
Пример #14
0
        private void terminalsTextBox_Leave(object sender, EventArgs e)
        {
            string newTerminals = terminalsTextBox.Text;

            GrammarProvider.GetGrammar().Terminals.Clear();

            foreach (var terminal in newTerminals)
            {
                if (GrammarProvider.GetGrammar().IsValidTerminal(terminal))
                {
                    GrammarProvider.GetGrammar().Terminals.Add(terminal);
                }
                else
                {
                    MessageBox.Show("!");
                }
            }
        }
Пример #15
0
        private static List <char> ListaDeNeterminaleCareDucInLambda(Grammar g)
        {
            int i = 0;

            List <char>[] N = new List <char> [100];
            N[i] = new List <char>(g.ProductionList.Where(x => x.Right.Equals("@"))
                                   .Select(x => x.Left).ToList());

            //foreach (var p in g.ProductionList)
            //{
            //    if (p.Right.Equals("@"))
            //    {
            //        N[i].Add(p.Left);
            //    }
            //}


            do
            {
                i++;
                N[i] = new List <char>(N[i - 1]);
                //foreach (var p in GrammarProvider.GetGrammar().ProductionList)
                //{
                //    if (Helper.StringHasOnlyCharsFromCharList(p.Right, N[i - 1]))
                //    {
                //        N[i].Add(p.Left);
                //    }
                //}
                //N[i] = N[i].Distinct().ToList();

                N[i].AddRange(GrammarProvider.GetGrammar().ProductionList
                              .Where(x => Helper.StringHasOnlyCharsFromCharList(x.Right, N[i - 1]))
                              .Select(x => x.Left));
                N[i] = N[i].Distinct().ToList();
            }while (!N[i].SequenceEqual(N[i - 1]));

            return(N[i]);
        }
Пример #16
0
 private void loadButton_Click(object sender, EventArgs e)
 {
     GrammarProvider.GetGrammar().LoadFromFile(Properties.Resources.DefaultGrammarLocation);
     grammarInfoWebBrowser.DocumentText = GrammarProvider.GetGrammar().GrammarInfoAsHTML();
 }
Пример #17
0
 private void saveButton_Click(object sender, EventArgs e)
 {
     GrammarProvider.GetGrammar().SaveToJson(Properties.Resources.DefaultGrammarLocation);
 }
Пример #18
0
        private void parseButton_Click(object sender, EventArgs e)
        {
            GrammarProvider.GetGrammar().Parse(inputTextBox.Text);

            grammarInfoWebBrowser.DocumentText = GrammarProvider.GetGrammar().GrammarInfoAsText();
        }
 private void noLambdaProductionsButton_Click(object sender, EventArgs e)
 {
     GrammarProvider.GetGrammar().EliminateLambdaProductions();
     grammarInfoWebBrowser.DocumentText = GrammarProvider.GetGrammar().GrammarInfoAsHTML();
 }
Пример #20
0
 private void deleteProductionButton_Click(object sender, EventArgs e)
 {
     GrammarProvider.GetGrammar().ProductionList.RemoveAt(productionsDataGridView.SelectedRows[0].Index);
     productionsDataGridView.DataSource = null;
     productionsDataGridView.DataSource = GrammarProvider.GetGrammar().ProductionList;
 }