Пример #1
0
        private static void TestAstPrinter()
        {
            // -123 * (45.67) => (* (- 123) (group 45.67))
            Expr expression =
                new Expr.Binary(
                    new Expr.Unary(
                        new Token(TokenType.MINUS, "-", null, 1),
                        new Expr.Literal(123)
                        ),
                    new Token(TokenType.STAR, "*", null, 1),
                    new Expr.Grouping(
                        new Expr.Literal(45.67)
                        )
                    );

            var printer = new AstPrinter();

            Console.WriteLine(expression.Accept(printer));
            Console.ReadLine();
        }
Пример #2
0
 public string VisitBinaryExpr(Expr.Binary expr)
 {
     return(Parenthesise(expr.Opr.Lexeme, expr.Left, expr.Right));
 }
Пример #3
0
 public Nothing VisitBinaryExpr(Expr.Binary expr)
 {
     Resolve(expr.Left);
     Resolve(expr.Right);
     return(Nothing.AtAll);
 }