Пример #1
0
        public override bool VisitMethod_invocation2([NotNull] calculatorParser.Method_invocation2Context context)
        {
            bool res = true;

            if (context.children != null)
            {
                foreach (IParseTree c in context.children)
                {
                    if (!Visit(c))
                    {
                        Results[context] = false;
                        return(false);
                    }
                }
            }
            if (context.ChildCount == 3)
            {
                bool r = Results[context.GetChild(1)];
                res &= r;
            }
            else if (context.ChildCount == 1)
            {
                var  child = context.GetChild(0);
                bool r     = Results[child];
                res &= r;
            }
            Results[context] = res;
            return(res);
        }
Пример #2
0
 public override bool VisitPrimary_expression([NotNull] calculatorParser.Primary_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 && context.GetChild(1) as calculatorParser.Method_invocation2Context != null)
     {
         bool res = false;
         calculatorParser.Method_invocation2Context mi =
             context.GetChild(1) as calculatorParser.Method_invocation2Context;
         string fun = context.GetChild(0).GetText();
         if (fun == "sin" ||
             fun == "cos" ||
             fun == "tan" ||
             fun == "arcsin" ||
             fun == "arccos" ||
             fun == "arctan" ||
             fun == "exp" ||
             fun == "ln")
         {
             if (mi.ChildCount == 3)
             {
                 bool rhs = Results[mi.GetChild(1)];
                 res = rhs;
                 Results[context] = res;
                 return(res);
             }
             else if (mi.ChildCount == 1)
             {
                 bool rhs = Results[mi.GetChild(0)];
                 res = rhs;
                 Results[context] = res;
                 return(res);
             }
         }
     }
     {
         Results[context] = false;
         return(false);
     }
 }
Пример #3
0
 public override Expression VisitPrimary_expression([NotNull] calculatorParser.Primary_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 && context.GetChild(1) as calculatorParser.Method_invocation2Context != null)
         {
             calculatorParser.Method_invocation2Context mi =
                 context.GetChild(1) as calculatorParser.Method_invocation2Context;
             string fun = context.GetChild(0).GetText();
             if (fun == "Sin" ||
                 fun == "Cos" ||
                 fun == "Tan" ||
                 fun == "Asin" ||
                 fun == "Acos" ||
                 fun == "Atan"
                 )
             {
                 Expression rhs = null;
                 if (mi.ChildCount == 3)
                 {
                     rhs = Results[mi.children[1]];
                 }
                 else if (mi.ChildCount == 1)
                 {
                     rhs = Results[mi.children[0]];
                 }
                 return(Expression.Call(typeof(Math).GetTypeInfo().GetDeclaredMethod(fun), rhs));
             }
         }
     }
     Results[context] = null;
     return(null);
 }