示例#1
0
        private void compilar()
        {
            if (arquivo == "")
            {
                salvarArquivo();
            }
            richTextBox2.Clear();
            Lexico lexico = new Lexico();

            Sintatico.Sintatico sintatico = new Sintatico.Sintatico();
            Semantico           semantico = null;

            Semantico.GetLimpa();
            semantico = Semantico.GetInstance();

            lexico.setInput(richTextBox1.Text);
            string arq = Path.GetFileNameWithoutExtension(statusStrip1.Items[1].ToString());

            semantico.NomeArq = arq;
            try
            {
                sintatico.parse(lexico, new Semantico());
                richTextBox2.AppendText("programa compilado com sucesso");
                this.compilado = true;
                Token t = null;

                /*  richTextBox2.AppendText("linha\t\tclasse\t\t\tlexema"+Environment.NewLine);
                 * while ( (t = lexico.nextToken()) != null )
                 * {
                 *    richTextBox2.AppendText(t.Position + "\t\t"+ t.getTipoToken() +"\t\t" +t.Lexeme +Environment.NewLine);
                 *
                 * }*/
            }
            catch (LexicalError e)
            {
                richTextBox2.Clear();
                richTextBox2.AppendText(" Erro na linha " + e.getPosition() + " - " + e.Message + Environment.NewLine);
            }
            catch (SyntaticError e)
            {
                richTextBox2.Clear();
                richTextBox2.AppendText(" Erro na linha " + e.getPosition() + " - " + e.Message + Environment.NewLine);
            }
            catch (SemanticError e)
            {
                richTextBox2.Clear();
                richTextBox2.AppendText(e.Message + Environment.NewLine);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            string codigo = "";

            System.IO.StreamReader file = new System.IO.StreamReader("C://Users/Dell/Documents/Visual Studio 2013/Projects/Compiladores/Compiladores/test.c");
            codigo = file.ReadToEnd().ToString();
            Lexico          lexico = new Lexico(codigo);
            SintacticoClass parser = new SintacticoClass(lexico);

            var Arbol = parser.Parser();

            foreach (var statementNode in Arbol)
            {
                statementNode.ValidSemantic();
                statementNode.Interpret();
                Console.WriteLine(statementNode.GenerarCodigo());
            }
            var s = ContenidoStack.InstanceStack.Stack;

            Console.ReadKey();
        }