コード例 #1
0
        public override Expression VisitInt([NotNull] CalcLangParser.IntContext context)
        {
            // strip off the underscores
            string text = context.Integer().GetText().Replace("_", "");

            int numBase = 10;

            if (text.StartsWith("0x"))
            {
                text    = text.Substring(2);
                numBase = 16;
            }
            else if (text.StartsWith("0o"))
            {
                text    = text.Substring(2);
                numBase = 8;
            }
            else if (text.StartsWith("0b"))
            {
                text    = text.Substring(2);
                numBase = 2;
            }

            (int index, int length) = ExpressionIndexAndLength(context.SourceInterval);

            BigInteger result = HornerScheme(text, numBase);

            if (result <= long.MaxValue)
            {
                return(new PrimitiveExpression(index, length, (long)result));
            }

            return(new PrimitiveExpression(index, length, result));
        }
コード例 #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>Int</c>
 /// labeled alternative in <see cref="CalcLangParser.expression"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitInt([NotNull] CalcLangParser.IntContext context)
 {
     return(VisitChildren(context));
 }
コード例 #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>Int</c>
 /// labeled alternative in <see cref="CalcLangParser.expression"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitInt([NotNull] CalcLangParser.IntContext context)
 {
 }