minor refactorings at parser and tokenizer

This commit is contained in:
hneemann 2016-07-03 18:30:13 +02:00
parent 9abddfdf97
commit 5d9018a8c5
3 changed files with 14 additions and 7 deletions

View File

@ -53,7 +53,7 @@ public class Parser {
private Expression parseOr() throws IOException, ParseException {
Expression ex = parseAnd();
while (tokenizer.peek() == OR) {
tokenizer.next();
tokenizer.consume();
ex = Operation.or(ex, parseAnd());
}
return ex;
@ -62,7 +62,7 @@ public class Parser {
private Expression parseAnd() throws IOException, ParseException {
Expression ex = parseSimpleExp();
while (tokenizer.peek() == AND) {
tokenizer.next();
tokenizer.consume();
ex = Operation.and(ex, parseSimpleExp());
}
return ex;

View File

@ -39,14 +39,21 @@ public class Tokenizer {
* @throws IOException IOException
*/
public Token next() throws IOException {
peek();
isToken = false;
Token token = peek();
consume();
return token;
}
/**
* peeks the next token.
* The token is kept in the stream, so next will return this token again!
* Consumes the token after a peek call
*/
public void consume() {
isToken = false;
}
/**
* Peeks the next token.
* The token is kept in the stream, so next() or peek() will return this token again!
*
* @return the token
* @throws IOException IOException

View File

@ -65,7 +65,7 @@ public class ParserTest extends TestCase {
}
public void testParseRegression2() throws Exception {
Parser p = new Parser("(C B) ∧ (A C) ∧ (B !C) ∧ (C !A)");
Parser p = new Parser("(C B) ∧ (A C) ∧ (B ¬C) ∧ (C ¬A)");
Expression e = p.parse();
Expression simplified = QuineMcCluskey.simplify(e);
assertTrue(simplified instanceof Operation.And);