예제 #1
0
        public override EExpressionType VisitNum_expr([NotNull] GrammarParser.Num_exprContext context)
        {
            if (context.ChildCount == 1)
            {
                var element = context.GetChild(0).GetText();

                int result = 0;
                if (int.TryParse(element, out result))
                {
                    return(EExpressionType.Int);
                }
                else
                {
                    element = LookUp(element);

                    if (int.TryParse(element, out result))
                    {
                        return(EExpressionType.Int);
                    }
                }
                float result2 = 0;
                if (float.TryParse(element, out result2))
                {
                    return(EExpressionType.Float);
                }
                else
                {
                    element = LookUp(element);

                    if (float.TryParse(element, out result2))
                    {
                        return(EExpressionType.Float);
                    }
                }

                return(EExpressionType.Unknown);
            }
            else if (context.ChildCount == 3)
            {
                var lhs     = context.GetChild(0);
                var lhsType = Visit(lhs);

                var rhs     = context.GetChild(2);
                var rhsType = Visit(rhs);

                if (lhsType != rhsType)
                {
                    throw new Exception("Type missmatch");
                }
            }
            else
            {
                throw new NotImplementedException("Grammar has changed!");
            }

            return(base.VisitNum_expr(context));
        }
예제 #2
0
        public override void EnterNum_expr([NotNull] GrammarParser.Num_exprContext context)
        {
            if (context.ChildCount == 1)
            {
                if (!(int.TryParse(context.GetChild(0).GetText(), out var result)))
                {
                    LookUpScope(context.GetChild(0).GetText());
                }
            }

            base.EnterNum_expr(context);
        }
예제 #3
0
        public override bool VisitNum_expr([NotNull] GrammarParser.Num_exprContext context)
        {
            Console.WriteLine($"Numeric Expression {context.GetText()}");
            if (context.ChildCount == 1)
            {
                string expression = SearchAndReplace(context.GetChild(0).GetText());
                try
                {
                    var test = float.Parse(expression);
                    Console.WriteLine("Succesfully accepted!");
                }
                catch (Exception)
                {
                    Console.WriteLine("Error man");
                }
            }
            else
            {
            }


            return(base.VisitNum_expr(context));
        }