mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -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 {
|
private Expression parseOr() throws IOException, ParseException {
|
||||||
Expression ex = parseAnd();
|
Expression ex = parseAnd();
|
||||||
while (tokenizer.peek() == OR) {
|
while (tokenizer.peek() == OR) {
|
||||||
tokenizer.next();
|
tokenizer.consume();
|
||||||
ex = Operation.or(ex, parseAnd());
|
ex = Operation.or(ex, parseAnd());
|
||||||
}
|
}
|
||||||
return ex;
|
return ex;
|
||||||
@ -62,7 +62,7 @@ public class Parser {
|
|||||||
private Expression parseAnd() throws IOException, ParseException {
|
private Expression parseAnd() throws IOException, ParseException {
|
||||||
Expression ex = parseSimpleExp();
|
Expression ex = parseSimpleExp();
|
||||||
while (tokenizer.peek() == AND) {
|
while (tokenizer.peek() == AND) {
|
||||||
tokenizer.next();
|
tokenizer.consume();
|
||||||
ex = Operation.and(ex, parseSimpleExp());
|
ex = Operation.and(ex, parseSimpleExp());
|
||||||
}
|
}
|
||||||
return ex;
|
return ex;
|
||||||
|
@ -39,14 +39,21 @@ public class Tokenizer {
|
|||||||
* @throws IOException IOException
|
* @throws IOException IOException
|
||||||
*/
|
*/
|
||||||
public Token next() throws IOException {
|
public Token next() throws IOException {
|
||||||
peek();
|
Token token = peek();
|
||||||
isToken = false;
|
consume();
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* peeks the next token.
|
* Consumes the token after a peek call
|
||||||
* The token is kept in the stream, so next will return this token again!
|
*/
|
||||||
|
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
|
* @return the token
|
||||||
* @throws IOException IOException
|
* @throws IOException IOException
|
||||||
|
@ -65,7 +65,7 @@ public class ParserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testParseRegression2() throws Exception {
|
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 e = p.parse();
|
||||||
Expression simplified = QuineMcCluskey.simplify(e);
|
Expression simplified = QuineMcCluskey.simplify(e);
|
||||||
assertTrue(simplified instanceof Operation.And);
|
assertTrue(simplified instanceof Operation.And);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user