mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 08:25:09 -04:00
minor refactorings at parser and tokenizer
This commit is contained in:
parent
9abddfdf97
commit
5d9018a8c5
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user