Exemplo n.º 1
0
        public Form1()
        {
            grammarLoader.Load(@"D:\TranslationSystems\parsegrammar2.txt");
            grammarLoader.CreateRecognizeTable();
            parser = new SyntaxParser.SyntaxParser(grammarLoader);
            lexer  = new Lex.Lex();
            InitializeComponent();
            ReadCode.MouseClick += (o, e) =>
            {
                using (StreamReader sr = new StreamReader(@"D:\code.txt"))
                {
                    CodeBox.Text = sr.ReadToEnd();
                }
            };
            GrammarLoad.Click += (o, e) =>
            {
                //try
                //{

                //    if (parser.IsParsed(lexs_bag.Lexems.ToList()))
                //    {
                //        ErrorsBox.Text += "Complete";
                //    }
                //    else
                //    {
                //        ErrorsBox.Text += "Failed";
                //    }
                //}
                //catch (Exception ex)
                //{
                //    ErrorsBox.Text = ex.Message;
                //}
            };
            AnalysButton.MouseClick += (o, e) =>
            {
                try
                {
                    IList <SyntaxParser.Operation> opers;

                    var lexs_bag = lexer.Analys(CodeBox.Lines);
                    if (parser.IsParsed(lexs_bag.Lexems.ToList(), out opers))
                    {
                        var codegen = new CodeGenerator();
                        ErrorsBox.Lines = codegen.generate(opers).Split('\n');

                        //ErrorsBox.Text = "Complete";
                        //ErrorsBox.Text = tree.ToString();
                        //CodeBox.Lines = tree.toStringArr().ToArray();
                    }
                    else
                    {
                        ErrorsBox.Text = "Failed";
                    }
                }
                catch (Exception ex)
                {
                    ErrorsBox.Text = ex.Message;
                }
                //var generator = new CodeGenerator();
                //ErrorsBox.Text = generator.Execute(generator.CreateOutputArray(CodeBox.Lines[0])).ToString();
            };
            CodeBox.TextChanged += (o, e) =>
            {
                string[] nums = new string[CodeBox.Lines.Length];
                for (int i = 1; i <= CodeBox.Lines.Length; i++)
                {
                    nums[i - 1] = i.ToString();
                }
                numericCode.Lines = nums;
            };
            CodeBox.VScroll += (o, e) =>
            {
                numericCode.Select(numericCode.Text.Length - 1, 0);
                numericCode.ScrollToCaret();
            };
        }
Exemplo n.º 2
0
 public static bool ProcessArguments(string[] args)
 {
     for (int i = 0; i < args.Length; i++)
     {
         string text = args[i];
         if (text[0] == '/')
         {
             int num = text.IndexOf(':');
             if (num >= 0)
             {
                 Lex.currentOption = text.Substring(1, num - 1).Trim();
                 Lex.currentValue  = text.Substring(num + 1).Trim();
                 string a;
                 if ((a = Lex.currentOption.ToLower()) != null)
                 {
                     if (!(a == "v") && !(a == "version"))
                     {
                         if (a == "help")
                         {
                             Lex.DisplayHelp();
                             return(false);
                         }
                     }
                     else
                     {
                         if (Lex.currentValue == "1")
                         {
                             Lex.version = 1;
                             goto IL_13C;
                         }
                         if (Lex.currentValue == "2")
                         {
                             Lex.version = 2;
                             goto IL_13C;
                         }
                         throw new ApplicationException("Invalid version number. Specify either '1' or '2'.");
                     }
                 }
                 throw new ApplicationException("Unknown option.");
             }
             Lex.currentOption = text.Substring(1).Trim();
             Lex.currentOption.ToLower();
             throw new ApplicationException("Unknown option.");
         }
         else
         {
             if (Lex.inFile == null)
             {
                 Lex.inFile = text;
             }
             else
             {
                 if (Lex.outFile != null)
                 {
                     Lex.currentOption = text;
                     throw new ApplicationException("Invalid option.");
                 }
                 Lex.outFile = text;
             }
         }
         IL_13C :;
     }
     if (Lex.outFile == null)
     {
         Lex.outFile = Path.ChangeExtension(Lex.inFile, ".cs");
     }
     return(true);
 }