LexAn Symbols
This commit is contained in:
parent
8c6828041d
commit
42fe2bf270
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,2 +1 @@
|
|||||||
'a'
|
= , && || ! == != > < >= <= + - * / % ^ ( )
|
||||||
'\n'
|
|
@ -123,10 +123,11 @@ public class LexAn implements AutoCloseable {
|
|||||||
* {@link peekToken} in {@link takeToken}.
|
* {@link peekToken} in {@link takeToken}.
|
||||||
*/
|
*/
|
||||||
private void nextToken() {
|
private void nextToken() {
|
||||||
while (buffChar == '\n') {
|
while (buffChar == ' ' || buffChar == '\n' || buffChar == '\t' || buffChar == '\r') {
|
||||||
nextChar();
|
nextChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Report.Location start = currentLocation();
|
||||||
switch (buffChar) {
|
switch (buffChar) {
|
||||||
case -1: // EOF
|
case -1: // EOF
|
||||||
buffToken = new Token(currentLocation(), Token.Symbol.EOF, null);
|
buffToken = new Token(currentLocation(), Token.Symbol.EOF, null);
|
||||||
@ -139,6 +140,130 @@ public class LexAn implements AutoCloseable {
|
|||||||
case '"':
|
case '"':
|
||||||
stringConst();
|
stringConst();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case '=':
|
||||||
|
nextChar();
|
||||||
|
if (buffChar == '=') {
|
||||||
|
buffToken = new Token(
|
||||||
|
new Report.Location(start, currentLocation()),
|
||||||
|
Token.Symbol.EQU,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffToken = new Token(start, Token.Symbol.ASSIGN, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case ',':
|
||||||
|
buffToken = new Token(currentLocation(), Token.Symbol.COMMA, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '&':
|
||||||
|
nextChar();
|
||||||
|
if (buffChar != '&') {
|
||||||
|
throw new Report.Error(currentLocation(), "Invalid character '" + (char) buffChar + "'");
|
||||||
|
}
|
||||||
|
buffToken = new Token(new Report.Location(start, currentLocation()), Token.Symbol.AND, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '|':
|
||||||
|
nextChar();
|
||||||
|
if (buffChar != '|') {
|
||||||
|
throw new Report.Error(currentLocation(), "Invalid character '" + (char) buffChar + "'");
|
||||||
|
}
|
||||||
|
buffToken = new Token(new Report.Location(start, currentLocation()), Token.Symbol.OR, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '!':
|
||||||
|
nextChar();
|
||||||
|
if (buffChar == '=') {
|
||||||
|
buffToken = new Token(
|
||||||
|
new Report.Location(start, currentLocation()),
|
||||||
|
Token.Symbol.NEQ,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffToken = new Token(start, Token.Symbol.NOT, null);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '>':
|
||||||
|
nextChar();
|
||||||
|
if (buffChar == '=') {
|
||||||
|
buffToken = new Token(
|
||||||
|
new Report.Location(start, currentLocation()),
|
||||||
|
Token.Symbol.GEQ,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffToken = new Token(start, Token.Symbol.GTH, null);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '<':
|
||||||
|
nextChar();
|
||||||
|
if (buffChar == '=') {
|
||||||
|
buffToken = new Token(
|
||||||
|
new Report.Location(start, currentLocation()),
|
||||||
|
Token.Symbol.LEQ,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffToken = new Token(start, Token.Symbol.LTH, null);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '+':
|
||||||
|
buffToken = new Token(currentLocation(), Token.Symbol.ADD, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '-':
|
||||||
|
buffToken = new Token(currentLocation(), Token.Symbol.SUB, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '*':
|
||||||
|
buffToken = new Token(currentLocation(), Token.Symbol.MUL, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '/':
|
||||||
|
buffToken = new Token(currentLocation(), Token.Symbol.DIV, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '%':
|
||||||
|
buffToken = new Token(currentLocation(), Token.Symbol.MOD, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '^':
|
||||||
|
buffToken = new Token(currentLocation(), Token.Symbol.PTR, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case '(':
|
||||||
|
buffToken = new Token(currentLocation(), Token.Symbol.LPAREN, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case ')':
|
||||||
|
buffToken = new Token(currentLocation(), Token.Symbol.RPAREN, null);
|
||||||
|
nextChar();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffChar >= '0' && buffChar <= '9') {
|
if (buffChar >= '0' && buffChar <= '9') {
|
||||||
@ -238,6 +363,9 @@ public class LexAn implements AutoCloseable {
|
|||||||
nextChar();
|
nextChar();
|
||||||
|
|
||||||
while (buffChar != '"') {
|
while (buffChar != '"') {
|
||||||
|
if (buffChar == -1) {
|
||||||
|
throw new Report.Error(currentLocation(), "Unterminated string.");
|
||||||
|
}
|
||||||
if (!isChar()) {
|
if (!isChar()) {
|
||||||
throw new Report.Error(currentLocation(), "Invalid character '" + (char) buffChar + "'.");
|
throw new Report.Error(currentLocation(), "Invalid character '" + (char) buffChar + "'.");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user