Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Digite o nome do arquivo: ");
                string fileName    = "prog.isi";// Console.ReadLine();
                string progContent = File.ReadAllText($"..\\..\\..\\{fileName}");

                AntlrInputStream  inputStream       = new AntlrInputStream(progContent);
                IsicompLexer      lexer             = new IsicompLexer(inputStream);
                CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
                IsicompParser     parser            = new IsicompParser(commonTokenStream);
                parser.programa();

                //AntlrInputStream inputStream = new AntlrInputStream(text.ToString());
                //SpeakLexer speakLexer = new SpeakLexer(inputStream);
                //CommonTokenStream commonTokenStream = new CommonTokenStream(speakLexer);
                //SpeakParser speakParser = new SpeakParser(commonTokenStream);
                //SpeakParser.ChatContext chatContext = speakParser.chat();
                //SpeakVisitor visitor = new SpeakVisitor();
                //visitor.Visit(chatContext);

                //foreach (var line in visitor.Lines)
                //{
                //    Console.WriteLine("{0} has said \"{1}\"", line.Person, line.Text);
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);
            }
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Digite o nome do arquivo: ");
                string fileName = Console.ReadLine();
                Console.WriteLine("Digite 1 para java e 2 para C");
                int language = int.Parse(Console.ReadLine());
                Console.WriteLine("Digite o nome do arquivo a ser gerado.");
                string nomeDoArquivo = Console.ReadLine();
                string progContent   = File.ReadAllText($"..\\..\\{fileName}");

                byte[]       byteArray = Encoding.UTF8.GetBytes(progContent);
                MemoryStream stream    = new MemoryStream(byteArray);

                IsicompLexer  lexer  = new IsicompLexer(stream);
                IsicompParser parser = new IsicompParser(lexer);
                parser.ProgramaObj = new Programa(nomeDoArquivo);
                parser.programa();
                if (language == 1)
                {
                    parser.ProgramaObj.saveToFile(Programa.Linguagem.JAVA);
                }
                else if (language == 2)
                {
                    parser.ProgramaObj.saveToFile(Programa.Linguagem.C);
                }
                else
                {
                    Console.WriteLine("Inválido");
                }
            }
            catch (ApplicationException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
            catch (TokenStreamRecognitionException ex)
            {
                Console.WriteLine($"{ex.Message} at {ex.recog.line}:{ex.recog.column}");
            }
            finally
            {
                Console.WriteLine("Fim.");
                Console.ReadKey();
            }
        }