mirror of
https://github.com/Noratrieb/GRSBPL.git
synced 2026-01-16 04:35:03 +01:00
other number support
This commit is contained in:
parent
e8967b3273
commit
02afd00fd3
1 changed files with 24 additions and 3 deletions
|
|
@ -128,13 +128,34 @@ public class Lexer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void number() {
|
private void number() {
|
||||||
|
int radix = 10;
|
||||||
|
if (last() == '0') {
|
||||||
|
if (peek() == 'x') {
|
||||||
|
consume();
|
||||||
|
consume();
|
||||||
|
radix = 16;
|
||||||
|
} else if (peek() == 'b') {
|
||||||
|
consume();
|
||||||
|
consume();
|
||||||
|
radix = 2;
|
||||||
|
} else if (peek() == 'o') {
|
||||||
|
consume();
|
||||||
|
consume();
|
||||||
|
radix = 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
StringBuilder number = new StringBuilder(String.valueOf(last()));
|
StringBuilder number = new StringBuilder(String.valueOf(last()));
|
||||||
while (Character.isDigit(peek())) {
|
|
||||||
number.append(advance());
|
while (isAlphaNumeric(peek())) {
|
||||||
|
char c = advance();
|
||||||
|
if (c != '_') {
|
||||||
|
number.append(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
int value = Integer.parseInt(number.toString());
|
int value = Integer.parseInt(number.toString(), radix);
|
||||||
add(CHARACTER, value);
|
add(CHARACTER, value);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw lexException("Value not an integer: " + number);
|
throw lexException("Value not an integer: " + number);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue