예제 #1
0
        void BtnParse_Click(object sender, EventArgs ent)
        {
            foreach (Control control in Controls)
            {
                if (!(control is TextBox)) continue;

                control.Focus();
                if (!Validate()) return;
            }

            try
            {
                var parser = new CLRParser(txtGrammarFile.Text.Trim());

                using (var stream = new FileStream(txtParserFile.Text.Trim(), FileMode.Create))
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine("Grammar >>>");
                    writer.WriteLine(parser.Grammar);
                    writer.WriteLine(Parser.Parser.SEPARATOR);
                    if (chkEntities.Checked)
                    {
                        writer.WriteLine("Grammar Entities >>>");
                        writer.WriteLine(parser.EntityCol);
                        writer.WriteLine(Parser.Parser.SEPARATOR);
                    }
                    if (chkFirstFollow.Checked)
                    {
                        writer.WriteLine("First & Follow >>>");
                        writer.WriteLine(parser.FirstnFollow());
                    }
                    if (chkGotoTable.Checked)
                    {
                        writer.WriteLine("Closures >>>");
                        writer.WriteLine(parser.ClouresGoToTable());
                    }

                    if (chkSLRTable.Checked) writer.WriteLine("SLR Table >>>");
                    //writer.WriteLine(parser.LALRTable());
                    writer.Close();
                }
            }
            catch (FileNotFoundException expNoFile)
            {
                MessageBox.Show(expNoFile.Message);
            }
            catch (IOException expIO)
            {
                MessageBox.Show(expIO.Message);
            }
            catch (FormatException expFormat)
            {
                MessageBox.Show(expFormat.Message);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }
예제 #2
0
        public static void WriteToFile(CLRParser parser, String fnOut)
        {
            try
            {
                // Write to Output File
                using (var stream = new FileStream(fnOut, FileMode.Create))
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine("Grammar >>>");
                    writer.WriteLine(parser.Grammar);
                    writer.WriteLine(Parser.Parser.SEPARATOR);
                    writer.WriteLine("Grammar Entities >>>");
                    writer.WriteLine(parser.EntityCol);
                    writer.WriteLine(Parser.Parser.SEPARATOR);
                    writer.WriteLine("First & Follow >>>");
                    writer.WriteLine(parser.FirstnFollow());
                    writer.WriteLine("Closures >>>");
                    writer.WriteLine(parser.ClouresGoToTable());
                    writer.WriteLine(parser.LALRTable());
                    writer.Close();
                }

                /*
                var g = GrammarIO.ReadGrammar(args[ 0 ]);

                Console.WriteLine(g);
                var eSet = g.Entities;

                StringBuilder sb = new StringBuilder();
                foreach( Entity entity in eSet )
                {
                    //// if grammar is not left recursive
                    sb.AppendLine("FIRST( " + entity + " ) : " + g.First(entity));

                    if( entity is NonTerminal )
                        sb.AppendLine("FOLLOW( " + entity + " ) : " + g.Follow(entity));
                }
                sb.Append("--------");
                Console.WriteLine(sb.ToString());

                Console.Read();
                */
            }
            catch (FileNotFoundException expNoFile)
            {
                Console.WriteLine(expNoFile);
            }
            catch (IOException expIO)
            {
                Console.WriteLine(expIO);
            }
            catch (FormatException expFormat)
            {
                Console.WriteLine(expFormat);
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }