コード例 #1
0
        public static UnifiedIntegerLiteral CreateDecimalLiteral(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "DECIMAL_LITERAL");

            /*
             * DECIMAL_LITERAL : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
             */
            var result = LiteralFuzzyParser.ParseBigInteger(node.Value);

            return(UnifiedIntegerLiteral.CreateInt32(result));
        }
コード例 #2
0
        public static UnifiedIntegerLiteral CreateOctalLiteral(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "OCTAL_LITERAL");

            /*
             * OCTAL_LITERAL : '0' ('0'..'7')+ IntegerTypeSuffix? ;
             */
            var result =
                LiteralFuzzyParser.ParseOcatleBigInteger(
                    node.Value.Substring(1));

            return(UnifiedIntegerLiteral.CreateInt32(result));
        }
コード例 #3
0
        // literals
        public static UnifiedIntegerLiteral CreateHexLiteral(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "HEX_LITERAL");

            /*
             * HEX_LITERAL : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
             */
            var result =
                LiteralFuzzyParser.ParseHexicalBigInteger(
                    node.Value.Substring(2));

            return(UnifiedIntegerLiteral.CreateInt32(result));
        }
コード例 #4
0
 public UnifiedElement VisitPrimitiveExpression(
     PrimitiveExpression prim, object data)
 {
     if (prim.Value == null)
     {
         return(UnifiedNullLiteral.Create());
     }
     if (prim.Value is bool)
     {
         return(UnifiedBooleanLiteral.Create((bool)prim.Value));
     }
     if (prim.Value is Int32)
     {
         return(UnifiedIntegerLiteral.CreateInt32((Int32)prim.Value));
     }
     if (prim.Value is UInt32)
     {
         return(UnifiedIntegerLiteral.CreateUInt32((UInt32)prim.Value));
     }
     if (prim.Value is Int64)
     {
         return(UnifiedIntegerLiteral.CreateInt64((Int64)prim.Value));
     }
     if (prim.Value is UInt64)
     {
         return(UnifiedIntegerLiteral.CreateUInt64((UInt64)prim.Value));
     }
     if (prim.Value is Single)
     {
         return(UnifiedFractionLiteral.Create(
                    (Single)prim.Value, UnifiedFractionLiteralKind.Single));
     }
     if (prim.Value is double)
     {
         return(UnifiedFractionLiteral.Create(
                    (double)prim.Value, UnifiedFractionLiteralKind.Double));
     }
     if (prim.Value is char)
     {
         return(UnifiedCharLiteral.Create(((char)prim.Value).ToString()));
     }
     if (prim.Value is string)
     {
         return(UnifiedStringLiteral.Create(prim.LiteralValue));
     }
     throw new NotImplementedException(
               "value type is " + prim.Value.GetType());
 }
コード例 #5
0
 private static UnifiedExpression CreateRange(XElement node)
 {
     Contract.Requires(node != null);
     Contract.Requires(node.Name() == "Range");
     if (node.Value.Contains("..."))
     {
         var numbers = node.Value.Split(
             new[] { "..." }, StringSplitOptions.None);
         return(UnifiedRange.CreateNotContainingMax(
                    UnifiedIntegerLiteral.CreateInt32(
                        LiteralFuzzyParser.ParseBigInteger(numbers[0])),
                    UnifiedIntegerLiteral.CreateInt32(
                        LiteralFuzzyParser.ParseBigInteger(numbers[1]))));
     }
     {
         var numbers = node.Value.Split(
             new[] { ".." }, StringSplitOptions.None);
         return(UnifiedRange.Create(
                    UnifiedIntegerLiteral.CreateInt32(
                        LiteralFuzzyParser.ParseBigInteger(numbers[0])),
                    UnifiedIntegerLiteral.CreateInt32(
                        LiteralFuzzyParser.ParseBigInteger(numbers[1]))));
     }
 }
コード例 #6
0
 private static UnifiedExpression CreateNumberToken(NumberToken <long> token)
 {
     return(UnifiedIntegerLiteral.CreateInt64(token.NumberValue));
 }
コード例 #7
0
 private static UnifiedExpression CreateNumberToken(NumberToken <uint> token)
 {
     return(UnifiedIntegerLiteral.CreateUInt32(token.NumberValue));
 }