Beispiel #1
0
        private void btn_syntax_Click(object sender, EventArgs e)
        {
            txt_result.Text = "";
            syntaxAnalyzer  = new Syntax(this.lexicalAnalyzer);
            syntaxAnalyzer.start();
            List <Error> syntaxErrors = syntaxAnalyzer.errorReporter();
            string       errorsText   = "";

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

            txt_result.Text = errorsText;

            if (lexicalAnalyzer.errorReporter().Count == 0 && syntaxAnalyzer.errorReporter().Count == 0)
            {
                txt_result.Text += ">>  no  lexical error :) \n>>  no  syntax  error :) \n>>  code compiled successfully :) \n>>  ";
            }
            else if (lexicalAnalyzer.errorReporter().Count == 0)
            {
                txt_result.Text += ">>  no  lexical error :) \n>>  ";
            }
            else
            {
                txt_result.Text += ">>  ";
            }
        }
Beispiel #2
0
        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 += ">>  ";
            }
        }
Beispiel #3
0
 public void start()
 {
     if (lexicalAnalyzer.errorReporter().Count > 0)
     {
         return;
     }
     else
     {
         stmts();
         pb.append("halt", "", "", "");
     }
 }
Beispiel #4
0
 public Syntax(Lexical lexical)
 {
     lexicalAnalyzer = lexical;
     if (lexicalAnalyzer.errorReporter().Count > 0)
     {
         Error error = new Error();
         error.analayzer   = "SyntaxAnalyzer";
         error.word        = "LexicalAnalyzerError";
         error.description = "lexical analyzer reported error . first check lexical errors";
         errors.Add(error);
     }
     else
     {
         LA = lexicalAnalyzer.nextToken();
     }
 }