public static IntegerLiteralExpression ParseIntegerLiteralExpression(antlr.IToken token, string s, bool asLong) { const string HEX_PREFIX = "0x"; NumberStyles style = NumberStyles.Integer | NumberStyles.AllowExponent; int hex_start = s.IndexOf(HEX_PREFIX); bool negative = false; if (hex_start >= 0) { if (s.StartsWith("-")) { negative = true; } s = s.Substring(hex_start + HEX_PREFIX.Length); style = NumberStyles.HexNumber; } long value = long.Parse(s, style, CultureInfo.InvariantCulture); if (negative) //negative hex number { value *= -1; } return(new IntegerLiteralExpression(SourceLocationFactory.ToLexicalInfo(token), value, asLong || (value > int.MaxValue || value < int.MinValue))); }
private static LexicalInfo ToLexicalInfo(IToken token) { return(SourceLocationFactory.ToLexicalInfo(token)); }