int Visit(MuldivContext context) { try { int l = (int)Visit(context.left); int r = (int)Visit(context.right); if (context.op.Type == MUL) { return(l * r); } else { if (r == 0) { throw new DivideByZeroException(); } else { return(l / r); } } } catch { Console.WriteLine("Las variables no son enteras"); return(0); } }
public override ASTN VisitMuldiv([NotNull] MuldivContext context) { ExprNode Leftexpr = (VisitExpr(context.left) as ExprNode); ExprNode Rigthexpr = (VisitExpr(context.right) as ExprNode); AritmethicNode node; if (context.op.Type == MUL) { node = new MulNode(context); } else { node = new DivNode(context); } node.Leftexpr = Leftexpr; node.Rigthexpr = Rigthexpr; return(node); }