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