Поддержка унарного логического отрицания

This commit is contained in:
Victor 2015-04-16 14:00:56 +03:00
parent 23ca118983
commit cbe463b149
3 changed files with 7 additions and 3 deletions

View File

@ -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;

View File

@ -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();
}

View File

@ -18,6 +18,7 @@ public enum TokenType {
RPAREN,
LBRACKET,
RBRACKET,
EXCL,
COLON,
// ключевые слова