Ejemplo n.º 1
0
 public override bool VisitUnary_expression([NotNull] calculatorParser.Unary_expressionContext context)
 {
     if (context.children != null)
     {
         foreach (var c in context.children)
         {
             if (!Visit(c))
             {
                 Results[context] = false;
                 return(false);
             }
         }
     }
     if (context.ChildCount == 1)
     {
         bool lhs = Results[context.GetChild(0)];
         Results[context] = lhs;
         return(lhs);
     }
     if (context.ChildCount == 2)
     {
         bool       rhs   = Results[context.GetChild(1)];
         bool       res   = rhs;
         IParseTree op_pt = context.GetChild(0);
         string     op    = op_pt.GetText();
         Results[context] = res;
         return(res);
     }
     {
         bool res = false;
         Results[context] = res;
         return(res);
     }
 }
Ejemplo n.º 2
0
 public override Expression VisitUnary_expression([NotNull] calculatorParser.Unary_expressionContext context)
 {
     if (context.children != null)
     {
         foreach (IParseTree c in context.children)
         {
             Visit(c);
         }
     }
     if (_completeness.Results[context])
     {
         if (context.ChildCount == 1)
         {
             Expression lhs = Results[context.GetChild(0)];
             Results[context] = lhs;
             return(lhs);
         }
         if (context.ChildCount == 2)
         {
             Expression rhs   = Results[context.children[1]];
             IParseTree op_pt = context.GetChild(0);
             string     op    = op_pt.GetText();
             if (op == "+")
             {
                 return(Expression.UnaryPlus(rhs));
             }
             else if (op == "-")
             {
                 return(Expression.Negate(rhs));
             }
         }
     }
     Results[context] = null;
     return(null);
 }