diff --git a/AlgebraicDataflowArchitectureModel/src/code/ast/NumberUtil.java b/AlgebraicDataflowArchitectureModel/src/code/ast/NumberUtil.java index 7d07105..dd076e8 100644 --- a/AlgebraicDataflowArchitectureModel/src/code/ast/NumberUtil.java +++ b/AlgebraicDataflowArchitectureModel/src/code/ast/NumberUtil.java @@ -16,7 +16,7 @@ * @return {@code true} if the given string represents a valid hexadecimal number, * {@code false} otherwise. * @apiNote This method returns {@code true} if the given token is a valid hexadecimal number representaion in Java source code. - * So make sure that the specification of this method is determined by Java language specification. + * So make sure that the specification of this method is determined by Java language specification. Hexadecimal Floating-Point is not supported yet. */ public static boolean isHexNumber(String token) { if (token == null) { @@ -42,14 +42,38 @@ return false; } - char prev = lexer.peek(); + char prev = 'x'; // Prior character is 'x' + boolean hasDigit = false; + while (lexer.peek() != '\0') { char c = lexer.advance(); - boolean isValidFormat = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c == '_'); + + if (c == 'l') { + // Suffix for long literal must be the last character in the literal. + if (lexer.peek() != '\0') { + return false; + } + + // Suffix must NOT be located right after an underscore + if (prev == '_') { + return false; + } + + // Finish checking the format + break; + } + + boolean isDigit = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'); + boolean isValidFormat = isDigit || (c == '_'); + if (!isValidFormat) { return false; } + if (isDigit) { + hasDigit = true; + } + // Save the previous character prev = c; } @@ -59,6 +83,10 @@ return false; } + if (!hasDigit) { + return false; + } + return true; } }