// 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); }
public abstract T Visit(GreaterThanNode node, object obj);
// Greater than operator public override string Visit(GreaterThanNode node, object obj) { return($"{Visit(node.Left)} > {Visit(node.Right)}"); }
// Greater than operator public override TypeNode Visit(GreaterThanNode node, object obj) { return(VisitComparisonNode(node)); // Call generic comparison visit method }