private void TerminalViewer_Click(object sender, ItemClickEventArgs e) { TokenViewer tokenViewer = (TokenViewer)e.ClickedItem; if (tokenViewer.Type != TokenType.Epsilon) { try { Candidate.First(elem => elem.Type == TokenType.Epsilon); } catch (Exception) { Candidate.Add(new TokenViewer { Token = tokenViewer.Token, Type = TokenType.Terminal }); } } else if (Candidate.Count == 0) { Candidate.Add(new TokenViewer { Token = tokenViewer.Token, Type = TokenType.Epsilon }); } }
private void NonterminalViewer_Click(object sender, ItemClickEventArgs e) { TokenViewer tokenViewer = (TokenViewer)e.ClickedItem; StartNonterminal.Clear(); StartNonterminal.Add(tokenViewer); }
/// <summary> /// select and add one token into the right part of current production /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TerminalViewer_Click(object sender, ItemClickEventArgs e) { TokenViewer tokenViewer = (TokenViewer)e.ClickedItem; if (tokenViewer.Type != TokenType.Epsilon) { try { Candidate.First(elem => elem.Type == TokenType.Epsilon); // if epsilon token already added, the other tokens including epsilon // can not be chosen to add } catch (Exception) { Candidate.Add(new TokenViewer { Token = tokenViewer.Token, Type = TokenType.Terminal }); } } else { // the right part must be empty to add epsilon token Candidate.Clear(); Candidate.Add(new TokenViewer { Token = tokenViewer.Token, Type = TokenType.Epsilon }); } }
private void SetStart_Click(object sender, RoutedEventArgs e) { string nonterminal = (string)(((MenuFlyoutItem)sender).DataContext); if (StartNonterminal != null) { Nonterminals.Remove(Nonterminals.First(elem => elem.Token == StartNonterminal.Token)); // reset the past starter Nonterminals.Add(new TokenViewer { Token = StartNonterminal.Token, IsStart = false, Type = TokenType.Nonterminal }); } // reset the current starter Nonterminals.Remove(Nonterminals.First(elem => elem.Token == nonterminal)); StartNonterminal = new TokenViewer { Token = nonterminal, IsStart = true, Type = TokenType.Nonterminal }; Nonterminals.Add(StartNonterminal); }
private void TokenViewer_Click(object sender, ItemClickEventArgs e) { TokenViewer tokenViewer = (TokenViewer)e.ClickedItem; Statement.Add(new TokenViewer { Token = tokenViewer.Token, IsStart = tokenViewer.IsStart, Type = tokenViewer.Type }); }
private void DeleteViewer_Click(object sender, ItemClickEventArgs e) { ToDeleteToken = (TokenViewer)e.ClickedItem; }
public object Convert(object value, Type targetType, object parameter, string language) { TokenViewer token = (TokenViewer)value; return(token.Token); }
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)); } }