modify parser
This commit is contained in:
@@ -10,3 +10,4 @@ anf = "anf.cli:main"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
pythonpath = ["src"]
|
||||
|
||||
+14
-5
@@ -10,8 +10,9 @@ TOKEN_RE = re.compile(
|
||||
\s*(
|
||||
\(|\)|
|
||||
!|
|
||||
\+|\*|
|
||||
AND|OR|
|
||||
OR|XOR|
|
||||
\+|⊕|
|
||||
AND|\*|⸱|
|
||||
0|1|
|
||||
X\d+|
|
||||
[A-Za-z_][A-Za-z0-9_]*
|
||||
@@ -53,16 +54,24 @@ class Parser:
|
||||
return p
|
||||
|
||||
def parse_or(self) -> Poly:
|
||||
left = self.parse_and()
|
||||
left = self.parse_xor()
|
||||
while self.peek() in ("OR", "+"):
|
||||
self.eat()
|
||||
right = self.parse_and()
|
||||
right = self.parse_xor()
|
||||
left = poly_xor(poly_xor(left, right), poly_and(left, right))
|
||||
return left
|
||||
|
||||
def parse_xor(self) -> Poly:
|
||||
left = self.parse_and()
|
||||
while self.peek() in ("XOR", "⊕"):
|
||||
self.eat()
|
||||
right = self.parse_and()
|
||||
left = poly_xor(left, right)
|
||||
return left
|
||||
|
||||
def parse_and(self) -> Poly:
|
||||
left = self.parse_not()
|
||||
while self.peek() in ("AND", "*"):
|
||||
while self.peek() in ("AND", "*", "⸱"):
|
||||
self.eat()
|
||||
right = self.parse_not()
|
||||
left = poly_and(left, right)
|
||||
|
||||
Reference in New Issue
Block a user