public void ParseInvalidUnexpectedCharacterString() { NonTerminal S, T, F; LR0 parser = new SLR1(LR0Test.ConstructTestGrammar(out S, out T, out F)); parser.Parse("((x)*t)**"); }
public void ParseInvalidEarlyTerminatingString() { NonTerminal S, T, F; LR0 parser = new SLR1(LR0Test.ConstructTestGrammar(out S, out T, out F)); parser.Parse("((x)*t)*"); }
public void ParseValidString() { NonTerminal S, T, F; LRParserBase parser = new SLR1(LR0Test.ConstructTestGrammar(out S, out T, out F)); ParseTree tree = parser.Parse("((x) * t) * foo"); Assert.IsNotNull(tree); Assert.IsNotNull(tree.Root); Assert.AreEqual(3, tree.Root.Children.Count); Assert.IsNotNull(tree.Root.Children[0].NonTerminal); Assert.AreEqual("*", tree.Root.Children[1].Token.Value); Assert.IsNotNull(tree.Root.Children[2].NonTerminal); Assert.AreEqual("foo", tree.Root.Children[2].Children[0].Token.Value); }
private void OpenFile_Click(object sender, EventArgs e) { OpenFileDialog fileName = new OpenFileDialog(); fileName.InitialDirectory = Application.StartupPath; fileName.Filter = "txt files (*.txt)|*.txt"; fileName.FilterIndex = 1; fileName.RestoreDirectory = true; if (fileName.ShowDialog() == DialogResult.OK) { //MessageBox.Show("OK"); string path = fileName.FileName.ToString(); backEnd = new SLR1(path); Dictionary <string, List <string> > rule = backEnd.GetRuleSet(); RuleDisplay.Clear(); if (rule == null) { MessageBox.Show("SLR1运行失败,输入的规则式有问题"); } else { foreach (string key in rule.Keys) { foreach (string showRule in rule[key]) { RuleDisplay.AppendText(key + "->" + showRule + "\r\n"); } } backEnd.SolveFirstSet(); backEnd.SolveFollowSet(); backEnd.BuildLR0ForView(); isSyntaxValid = backEnd.BuildTable(); MessageBox.Show("输入的规则式合法"); GetLR0.Enabled = true; } } }
public void SLR1InvalidGrammar() { LRParserBase parser = new SLR1(new CPointerHandling()); parser.Parse("x = y"); }
public void InputAlorithm(SLR1 al) { alogrithm = al; }