private void Compile()
        {
            characterCountLabel.Text = "" + codebox1.Text.Length;

            ICG_text.Text = "";
            richTextBox1.Text = "";
            errorTextBox.Text = "";
            treeView.Nodes.Clear();
            SemanticAnalyzer.globalSymbolTable = new List<GLOBAL>();
            SemanticAnalyzer.ClassSymbolTable = new List<CLASS>();
            SemanticAnalyzer.errors = new List<string>();
            classes_data.Text = "Select a Class";
            member_data.Text = "Select a Member";
            variables_data.Text = "Select a variable";
            classes_data.Items.Clear();
            member_data.Items.Clear();
            variables_data.Items.Clear();

            String errorText = "";
            LexAnalyzer lex = new LexAnalyzer();
            if (codebox1.Text.Length > 0)
            {
                wordBreaker = new breakWork();

                wordBreakerOutput = new List<token>();
                TokenOutput = new List<token>();

                wordBreakerOutput = wordBreaker.breakString(codebox1.Text);

                List<token> tokensList = lex.getTokensList(wordBreakerOutput);

                tokenSet = new List<token>();
                String lexError = "";
                foreach (token s in tokensList)
                {
                    if (s.wordStr != " " && s.wordStr != "\n" && s.wordStr != "\t" && s.wordStr != "\r")
                    {
                        //richTextBox1.Text += "(" + s.lineNumber + ") " + s.wordStr + "\n";
                        richTextBox1.Text += "(" + s.wordStr + ", " + s.classStr + ", " + s.lineNumber + ")\n";

                        token temp = new token(s.lineNumber, s.wordStr, s.classStr);
                        tokenSet.Add(temp);

                        if (s.classStr == Singleton.nonKeywords._INVALID.ToString())
                        {
                            lexError += s.wordStr + "\n";
                            lexicalErrorLabel.Text = lexError;
                            lexicalErrorLabel.ForeColor = System.Drawing.Color.Maroon;

                            errorText += "Lexical Error on Line Number " + s.lineNumber + ": " + s.wordStr + "\n";
                        }
                    }

                    if (lexError == "")
                    {
                        lexicalErrorLabel.Text = "No Error";
                        lexicalErrorLabel.ForeColor = System.Drawing.Color.Green;
                    }
                }

                SyntaxAnalyzer syntaxAnalysis = new SyntaxAnalyzer(tokenSet);
                if (syntaxAnalysis.validateCfg())
                {
                    syntaxErrorLabel.Text = "No Error";
                    syntaxErrorLabel.ForeColor = System.Drawing.Color.Green;

                    //TreeNode tree = new TreeNode("<S>");

                    //treeView.Nodes.Add(tree);
                }
                else
                {
                    syntaxErrorLabel.Text = "" + syntaxAnalysis.getErrors();
                    syntaxErrorLabel.ForeColor = System.Drawing.Color.Maroon;

                    errorText += "Syntax Error: " + syntaxAnalysis.getErrors();

                }
                if (syntaxAnalysis.getSemanticError() != "")
                {
                    errorText += "\n" + syntaxAnalysis.getSemanticError();
                    sementicErrorLabel.Text = "Errors";
                    sementicErrorLabel.ForeColor = System.Drawing.Color.Maroon;
                }
                else
                {
                    sementicErrorLabel.Text = "No Error";
                    sementicErrorLabel.ForeColor = System.Drawing.Color.Green;
                }
                totalTokenLabel.Text = "" + (tokenSet.Count - 1);
                totWordsLabel.Text = "" + (tokenSet.Count - 1);
                totLineLabel.Text = "" + wordBreakerOutput[wordBreakerOutput.Count - 1].lineNumber;

                if (errorText != "")
                {
                    errorTextBox.Text = errorText;
                }
                treeView.ExpandAll();
            }
        }
예제 #2
0
        private void Compile()
        {
            characterCountLabel.Text = "" + codebox1.Text.Length;

            ICG_text.Text     = "";
            richTextBox1.Text = "";
            errorTextBox.Text = "";
            treeView.Nodes.Clear();
            SemanticAnalyzer.globalSymbolTable = new List <GLOBAL>();
            SemanticAnalyzer.ClassSymbolTable  = new List <CLASS>();
            SemanticAnalyzer.errors            = new List <string>();
            classes_data.Text   = "Select a Class";
            member_data.Text    = "Select a Member";
            variables_data.Text = "Select a variable";
            classes_data.Items.Clear();
            member_data.Items.Clear();
            variables_data.Items.Clear();

            String      errorText = "";
            LexAnalyzer lex       = new LexAnalyzer();

            if (codebox1.Text.Length > 0)
            {
                wordBreaker = new breakWork();

                wordBreakerOutput = new List <token>();
                TokenOutput       = new List <token>();

                wordBreakerOutput = wordBreaker.breakString(codebox1.Text);

                List <token> tokensList = lex.getTokensList(wordBreakerOutput);

                tokenSet = new List <token>();
                String lexError = "";
                foreach (token s in tokensList)
                {
                    if (s.wordStr != " " && s.wordStr != "\n" && s.wordStr != "\t" && s.wordStr != "\r")
                    {
                        //richTextBox1.Text += "(" + s.lineNumber + ") " + s.wordStr + "\n";
                        richTextBox1.Text += "(" + s.wordStr + ", " + s.classStr + ", " + s.lineNumber + ")\n";

                        token temp = new token(s.lineNumber, s.wordStr, s.classStr);
                        tokenSet.Add(temp);

                        if (s.classStr == Singleton.nonKeywords._INVALID.ToString())
                        {
                            lexError += s.wordStr + "\n";
                            lexicalErrorLabel.Text      = lexError;
                            lexicalErrorLabel.ForeColor = System.Drawing.Color.Maroon;

                            errorText += "Lexical Error on Line Number " + s.lineNumber + ": " + s.wordStr + "\n";
                        }
                    }

                    if (lexError == "")
                    {
                        lexicalErrorLabel.Text      = "No Error";
                        lexicalErrorLabel.ForeColor = System.Drawing.Color.Green;
                    }
                }

                SyntaxAnalyzer syntaxAnalysis = new SyntaxAnalyzer(tokenSet);
                if (syntaxAnalysis.validateCfg())
                {
                    syntaxErrorLabel.Text      = "No Error";
                    syntaxErrorLabel.ForeColor = System.Drawing.Color.Green;

                    //TreeNode tree = new TreeNode("<S>");

                    //treeView.Nodes.Add(tree);
                }
                else
                {
                    syntaxErrorLabel.Text      = "" + syntaxAnalysis.getErrors();
                    syntaxErrorLabel.ForeColor = System.Drawing.Color.Maroon;

                    errorText += "Syntax Error: " + syntaxAnalysis.getErrors();
                }
                if (syntaxAnalysis.getSemanticError() != "")
                {
                    errorText += "\n" + syntaxAnalysis.getSemanticError();
                    sementicErrorLabel.Text      = "Errors";
                    sementicErrorLabel.ForeColor = System.Drawing.Color.Maroon;
                }
                else
                {
                    sementicErrorLabel.Text      = "No Error";
                    sementicErrorLabel.ForeColor = System.Drawing.Color.Green;
                }
                totalTokenLabel.Text = "" + (tokenSet.Count - 1);
                totWordsLabel.Text   = "" + (tokenSet.Count - 1);
                totLineLabel.Text    = "" + wordBreakerOutput[wordBreakerOutput.Count - 1].lineNumber;

                if (errorText != "")
                {
                    errorTextBox.Text = errorText;
                }
                treeView.ExpandAll();
            }
        }