Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     while (true)
     {
         Stream            inputStream = Console.OpenStandardInput();
         AntlrInputStream  input       = new AntlrInputStream(inputStream);
         CalculatorLexer   lexer       = new CalculatorLexer(input);
         CommonTokenStream tokens      = new CommonTokenStream(lexer);
         CalculatorParser  parser      = new CalculatorParser(tokens);
         parser.prog();
         Console.WriteLine("done");
         Console.ReadLine();
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var        inputStream = new StreamReader(Console.OpenStandardInput());
            var        input       = new AntlrInputStream(inputStream.ReadToEnd());
            var        lexer       = new CalculatorLexer(input);
            var        tokens      = new CommonTokenStream(lexer);
            var        parser      = new CalculatorParser(tokens);
            IParseTree tree        = parser.prog();

            Console.WriteLine(tree.ToStringTree(parser));
            var visitor = new CalculatorVisitor();

            Console.WriteLine(visitor.Visit(tree));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Stream            inputStream = Console.OpenStandardInput();
            AntlrInputStream  input       = new AntlrInputStream(inputStream);
            CalculatorLexer   lexer       = new CalculatorLexer(input);
            CommonTokenStream tokens      = new CommonTokenStream(lexer);
            CalculatorParser  parser      = new CalculatorParser(tokens);
            IParseTree        tree        = parser.prog();

            Console.WriteLine(tree.ToStringTree());

            Console.WriteLine("done"); //to know when it's done
            Console.ReadLine();        //to see the result
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            var        reader = new StringReader(Formula.Text);
            var        input  = new AntlrInputStream(reader.ReadToEnd());
            var        lexer  = new CalculatorLexer(input);
            var        tokens = new CommonTokenStream(lexer);
            var        parser = new CalculatorParser(tokens);
            IParseTree tree   = parser.prog();

            Tree.Text = tree.ToStringTree(parser);
            var visitor = new CalculatorVisitor();

            Result.Text = visitor.Visit(tree).ToString();
        }
Ejemplo n.º 5
0
 static void Main(string[] args)
 {
     try
     {
         StreamReader      inputStream = new StreamReader(Console.OpenStandardInput());
         AntlrInputStream  input       = new AntlrInputStream(inputStream.ReadToEnd());
         CalculatorLexer   lexer       = new CalculatorLexer(input);
         CommonTokenStream tokens      = new CommonTokenStream(lexer);
         CalculatorParser  parser      = new CalculatorParser(tokens);
         IParseTree        tree        = parser.prog();
         Console.WriteLine(tree.ToStringTree(parser));
         CalculatorVisitor visitor = new CalculatorVisitor();
         Console.WriteLine(visitor.Visit(tree));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     Console.ReadLine();
 }