modify parser

This commit is contained in:
2026-05-18 14:46:35 +02:00
parent 6258757605
commit 3f93c074ef
2 changed files with 15 additions and 5 deletions
+1
View File
@@ -10,3 +10,4 @@ anf = "anf.cli:main"
[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = ["src"]
+14 -5
View File
@@ -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)