1 // Generated from doc/examples/simple_expression/Expr.g4 by ANTLR 4.7.2
2 module PrintExprVisitor;
3 
4 import ExprBaseVisitor;
5 import std.variant : Variant;
6 import ExprParser : ExprParser;
7 
8 /**
9  * This class provides an empty implementation of {@link ExprVisitor},
10  * which can be extended to create a visitor which only needs to handle a subset
11  * of the available methods.
12  *
13  * @param Variant The return type of the visit operation. Use {@link void} for
14  * operations with no return type.
15  */
16 public class PrintExprVisitor : ExprBaseVisitor {
17     /**
18      * {@inheritDoc}
19      *
20      * <p>The default implementation returns the result of calling
21      * {@link #visitChildren} on {@code ctx}.</p>
22      */
23     override public Variant visitProg(ExprParser.ProgContext ctx) {
24         auto res = visit(ctx.children[0]).get!(int);
25         return Variant(res);
26     }
27 
28     /**
29      * {@inheritDoc}
30      *
31      * <p>The default implementation returns the result of calling
32      * {@link #visitChildren} on {@code ctx}.</p>
33      */
34     override public Variant visitDiv(ExprParser.DivContext ctx) {
35         auto res = visit(ctx.children[0]).get!(int) /
36             visit(ctx.children[2]).get!(int);
37         return Variant(res);
38     }
39     /**
40      * {@inheritDoc}
41      *
42      * <p>The default implementation returns the result of calling
43      * {@link #visitChildren} on {@code ctx}.</p>
44      */
45     override public Variant visitAdd(ExprParser.AddContext ctx) {
46         auto res = visit(ctx.children[0]).get!(int) +
47             visit(ctx.children[2]).get!(int);
48         return Variant(res);
49     }
50     /**
51      * {@inheritDoc}
52      *
53      * <p>The default implementation returns the result of calling
54      * {@link #visitChildren} on {@code ctx}.</p>
55      */
56     override public Variant visitSub(ExprParser.SubContext ctx) {
57         auto res = visit(ctx.children[0]).get!(int) -
58             visit(ctx.children[2]).get!(int);
59         return Variant(res);
60     }
61     /**
62      * {@inheritDoc}
63      *
64      * <p>The default implementation returns the result of calling
65      * {@link #visitChildren} on {@code ctx}.</p>
66      */
67     override public Variant visitMul(ExprParser.MulContext ctx) {
68         auto res = visit(ctx.children[0]).get!(int) *
69             visit(ctx.children[2]).get!(int);
70         return Variant(res);
71     }
72     /**
73      * {@inheritDoc}
74      *
75      * <p>The default implementation returns the result of calling
76      * {@link #visitChildren} on {@code ctx}.</p>
77      */
78     override public Variant visitBracketExpr(ExprParser.BracketExprContext ctx) {
79         auto res = visit(ctx.children[1]).get!(int);
80         return Variant(res);
81     }
82     /**
83      * The terminal element: interger number
84      */
85     override public Variant visitInt(ExprParser.IntContext ctx) {
86         import std.conv;
87         return Variant(to!int(ctx.getText.get!(string)));
88     }
89 }