예제 #1
0
파일: Form1.cs 프로젝트: mnfi3/comp
        private void btn_lexical_Click(object sender, EventArgs e)
        {
            txt_result.Text = "";
            string input = txt_code.Text;

            input = input.Replace("\t", "");

            string tokensText = "";

            lexicalAnalyzer = new Lexical(input);
            string[]     types   = lexicalAnalyzer.getTypes();
            string[]     lexemes = lexicalAnalyzer.getLexemes();
            List <Error> errors  = lexicalAnalyzer.errorReporter();

            for (int i = 0; i < types.Length; i++)
            {
                tokensText += lexemes[i] + "\t: " + types[i] + "\n";
            }

            string errorsText = "";

            for (int i = 0; i < errors.Count; i++)
            {
                errorsText += (i + 1).ToString() + " : error in " + errors[i].analayzer + "\t" + "'" + errors[i].word + "'" +
                              " " + errors[i].description + "\n\n";
            }



            txt_tokens.Text = tokensText;
            txt_result.Text = errorsText;


            if (lexicalAnalyzer.errorReporter().Count == 0 && input.Length > 1)
            {
                txt_result.Text += ">>  no  lexical error :) \n>>  ";
            }
            else
            {
                txt_result.Text += ">>  ";
            }
        }