예제 #1
0
 private void DeleteProduction_Click(object sender, RoutedEventArgs e)
 {
     if (ToDeleteProduction != null)
     {
         Productions.Remove(ToDeleteProduction);
     }
     ToDeleteProduction = null;
 }
예제 #2
0
 private void DeleteProductionViewer_Click(object sender, ItemClickEventArgs e)
 {
     ToDeleteProduction = (ProductionViewer)e.ClickedItem;
 }
예제 #3
0
        async private void OnLoadGrammarCallBack(List <string> nonterminals, List <string> terminals, List <string> productions, string start)
        {
            Nonterminals.Clear();
            Terminals.Clear();
            StartNonterminal = null;
            foreach (var item in nonterminals)
            {
                Nonterminals.Add(new TokenViewer
                {
                    Token   = item,
                    IsStart = false,
                    Type    = TokenType.Nonterminal
                });
            }
            foreach (var item in terminals)
            {
                Terminals.Add(new TokenViewer
                {
                    Token   = item,
                    IsStart = false,
                    Type    = TokenType.Terminal
                });
            }
            Terminals.Add(new TokenViewer
            {
                Token   = "ε",
                IsStart = false,
                Type    = TokenType.Epsilon
            });
            foreach (var item in Nonterminals)
            {
                if (item.Token.Equals(start))
                {
                    StartNonterminal         = item;
                    StartNonterminal.IsStart = true;
                }
            }

            ProductionsLoadByLocal = new ObservableCollection <ProductionViewer>();
            foreach (var item in productions)
            {
                string[] nonterminalAndCandidate = item.Split('#');
                if (nonterminalAndCandidate.Length != 2)
                {
                    ProductionsLoadByLocal = null;
                    break;
                }
                else
                {
                    try
                    {
                        ProductionViewer newProduction = new ProductionViewer
                        {
                            Nonterminal = Nonterminals.First(elem => elem.Token.Equals(nonterminalAndCandidate[0])),
                            Candidates  = new List <TokenViewer>()
                        };
                        string[] candidates = nonterminalAndCandidate[1].Split('.');
                        foreach (var elem in candidates)
                        {
                            if (!string.IsNullOrWhiteSpace(elem))
                            {
                                newProduction.Candidates.Add(Nonterminals.Concat(Terminals).First(e => e.Token.Equals(elem)));
                            }
                        }
                        ProductionsLoadByLocal.Add(newProduction);
                    }
                    catch (Exception)
                    {
                        ProductionsLoadByLocal = null;
                        break;
                    }
                }
            }

            if (Nonterminals.Count == 0 ||
                Terminals.Count == 0 ||
                StartNonterminal == null ||
                ProductionsLoadByLocal == null)
            {
                Nonterminals.Clear();
                Terminals.Clear();
                StartNonterminal = null;

                MessageDialog error = new MessageDialog("文件读取失败")
                {
                    Title = "错误"
                };
                error.Commands.Add(new UICommand("确定"));
                await error.ShowAsync();
            }
            else
            {
                this.Frame.Navigate(typeof(ProductionPage), Nonterminals.Concat(Terminals));
            }
        }