mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 23:36:27 -04:00
add also | and & as operations OR and AND.
This commit is contained in:
parent
445dc5393f
commit
d77cfcf6b1
@ -40,6 +40,8 @@ public class Parser {
|
|||||||
tokenizer.wordChars('_', '_');
|
tokenizer.wordChars('_', '_');
|
||||||
tokenizer.wordChars('^', '^');
|
tokenizer.wordChars('^', '^');
|
||||||
tokenizer.wordChars('0', '9');
|
tokenizer.wordChars('0', '9');
|
||||||
|
// tokenizer.ordinaryChar('∧'); StreamTokenizer can not handle ordinary chars > 255
|
||||||
|
// tokenizer.ordinaryChar('∨');
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNext(String str) throws IOException {
|
private boolean isNext(String str) throws IOException {
|
||||||
@ -76,7 +78,7 @@ public class Parser {
|
|||||||
|
|
||||||
private Expression parseOr() throws IOException, ParseException {
|
private Expression parseOr() throws IOException, ParseException {
|
||||||
Expression ex = parseAnd();
|
Expression ex = parseAnd();
|
||||||
while (isNext('+') || isNext("∨")) {
|
while (isNext('+') || isNext("∨") || isNext('|')) {
|
||||||
ex = Operation.or(ex, parseAnd());
|
ex = Operation.or(ex, parseAnd());
|
||||||
}
|
}
|
||||||
return ex;
|
return ex;
|
||||||
@ -84,7 +86,7 @@ public class Parser {
|
|||||||
|
|
||||||
private Expression parseAnd() throws IOException, ParseException {
|
private Expression parseAnd() throws IOException, ParseException {
|
||||||
Expression ex = parseSimpleExp();
|
Expression ex = parseSimpleExp();
|
||||||
while (isNext('*') || isNext("∧")) {
|
while (isNext('*') || isNext("∧") || isNext('&')) {
|
||||||
ex = Operation.and(ex, parseSimpleExp());
|
ex = Operation.and(ex, parseSimpleExp());
|
||||||
}
|
}
|
||||||
return ex;
|
return ex;
|
||||||
|
@ -21,15 +21,15 @@ public class ParserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testParseOr() throws Exception {
|
public void testParseOr() throws Exception {
|
||||||
Parser p = new Parser("a+b");
|
assertTrue(new Parser("a+b").parse() instanceof Operation.Or);
|
||||||
Expression exp = p.parse();
|
assertTrue(new Parser("a ∨ b").parse() instanceof Operation.Or);
|
||||||
assertTrue(exp instanceof Operation.Or);
|
assertTrue(new Parser("a|b").parse() instanceof Operation.Or);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseAnd() throws Exception {
|
public void testParseAnd() throws Exception {
|
||||||
Parser p = new Parser("a*b");
|
assertTrue(new Parser("a*b").parse() instanceof Operation.And);
|
||||||
Expression exp = p.parse();
|
assertTrue(new Parser("a ∧ b").parse() instanceof Operation.And);
|
||||||
assertTrue(exp instanceof Operation.And);
|
assertTrue(new Parser("a&b").parse() instanceof Operation.And);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseParenthesis() throws Exception {
|
public void testParseParenthesis() throws Exception {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user