mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Расширенные идентификаторы
This commit is contained in:
parent
8a3719d67d
commit
1cc4dc8f77
@ -232,3 +232,6 @@ xarr[0] += xarr[1]
|
|||||||
xarr[0] *= xarr[2]
|
xarr[0] *= xarr[2]
|
||||||
xarr[0]++
|
xarr[0]++
|
||||||
println xarr[0]
|
println xarr[0]
|
||||||
|
|
||||||
|
`extended word variable` = 9
|
||||||
|
println `extended word variable`
|
@ -116,6 +116,7 @@ public final class Lexer {
|
|||||||
final char current = peek(0);
|
final char current = peek(0);
|
||||||
if (Character.isDigit(current)) tokenizeNumber();
|
if (Character.isDigit(current)) tokenizeNumber();
|
||||||
else if (Character.isJavaIdentifierStart(current)) tokenizeWord();
|
else if (Character.isJavaIdentifierStart(current)) tokenizeWord();
|
||||||
|
else if (current == '`') tokenizeExtendedWord();
|
||||||
else if (current == '"') tokenizeText();
|
else if (current == '"') tokenizeText();
|
||||||
else if (current == '#') {
|
else if (current == '#') {
|
||||||
next();
|
next();
|
||||||
@ -206,6 +207,21 @@ public final class Lexer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void tokenizeExtendedWord() {
|
||||||
|
next();// skip `
|
||||||
|
clearBuffer();
|
||||||
|
char current = peek(0);
|
||||||
|
while (true) {
|
||||||
|
if (current == '\0') throw error("Reached end of file while parsing extended word.");
|
||||||
|
if (current == '\n' || current == '\r') throw error("Reached end of line while parsing extended word.");
|
||||||
|
if (current == '`') break;
|
||||||
|
buffer.append(current);
|
||||||
|
current = next();
|
||||||
|
}
|
||||||
|
next(); // skip closing `
|
||||||
|
addToken(TokenType.WORD, buffer.toString());
|
||||||
|
}
|
||||||
|
|
||||||
private void tokenizeText() {
|
private void tokenizeText() {
|
||||||
next();// skip "
|
next();// skip "
|
||||||
clearBuffer();
|
clearBuffer();
|
||||||
@ -216,6 +232,7 @@ public final class Lexer {
|
|||||||
current = next();
|
current = next();
|
||||||
switch (current) {
|
switch (current) {
|
||||||
case '"': current = next(); buffer.append('"'); continue;
|
case '"': current = next(); buffer.append('"'); continue;
|
||||||
|
case '0': current = next(); buffer.append('\0'); continue;
|
||||||
case 'b': current = next(); buffer.append('\b'); continue;
|
case 'b': current = next(); buffer.append('\b'); continue;
|
||||||
case 'f': current = next(); buffer.append('\f'); continue;
|
case 'f': current = next(); buffer.append('\f'); continue;
|
||||||
case 'n': current = next(); buffer.append('\n'); continue;
|
case 'n': current = next(); buffer.append('\n'); continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user