Поддержка унарного логического отрицания
This commit is contained in:
parent
23ca118983
commit
cbe463b149
@ -15,12 +15,12 @@ public final class Lexer {
|
||||
return new Lexer().process(input).getTokens();
|
||||
}
|
||||
|
||||
private static final String OPERATOR_CHARS = "=+-()[]$:";
|
||||
private static final String OPERATOR_CHARS = "=+-()[]!$:";
|
||||
private static final TokenType[] OPERATOR_TYPES = new TokenType[] {
|
||||
TokenType.EQ,
|
||||
TokenType.PLUS, TokenType.MINUS,
|
||||
TokenType.LPAREN, TokenType.RPAREN, TokenType.LBRACKET, TokenType.RBRACKET,
|
||||
TokenType.COMMAND, TokenType.COLON,
|
||||
TokenType.EXCL, TokenType.COMMAND, TokenType.COLON,
|
||||
};
|
||||
|
||||
private static final Map<String, TokenType> KEYWORDS;
|
||||
|
@ -377,7 +377,7 @@ public final class Parser {
|
||||
}
|
||||
|
||||
private boolean ifStatement() {
|
||||
final Expression condition = primary();
|
||||
final Expression condition = expression();
|
||||
consume(TokenType.COLON);
|
||||
|
||||
if (condition.eval() == 0) {
|
||||
@ -421,6 +421,9 @@ public final class Parser {
|
||||
if (match(TokenType.PLUS)) {
|
||||
return primary();
|
||||
}
|
||||
if (match(TokenType.EXCL)) {
|
||||
return new ValueExpression( primary().eval() != 0 ? 0 : 1 );
|
||||
}
|
||||
return primary();
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ public enum TokenType {
|
||||
RPAREN,
|
||||
LBRACKET,
|
||||
RBRACKET,
|
||||
EXCL,
|
||||
COLON,
|
||||
|
||||
// ключевые слова
|
||||
|
Loading…
Reference in New Issue
Block a user