コード例 #1
0
        // Infix comparison (greater than / less than)
        public override ASTNode VisitInfixComparison(CLUBSParser.InfixComparisonContext context)
        {
            SourcePosition      sourcePosition = new SourcePosition(context.start);
            InfixExpressionNode node;

            // Get the correct comparison operator by switching on the token
            switch (context.op.Type)
            {
            case CLUBSLexer.GT:
                node = new GreaterThanNode(sourcePosition);
                break;

            case CLUBSLexer.LT:
                node = new LessThanNode(sourcePosition);
                break;

            default:
                throw new Exception("Operator not found");
            }

            node.Left  = Visit(context.left) as ExpressionNode;
            node.Right = Visit(context.right) as ExpressionNode;

            return(node);
        }
コード例 #2
0
 public abstract T Visit(GreaterThanNode node, object obj);
コード例 #3
0
 // Greater than operator
 public override string Visit(GreaterThanNode node, object obj)
 {
     return($"{Visit(node.Left)} > {Visit(node.Right)}");
 }
コード例 #4
0
 // Greater than operator
 public override TypeNode Visit(GreaterThanNode node, object obj)
 {
     return(VisitComparisonNode(node)); // Call generic comparison visit method
 }