Syntax¶
pynmms.syntax.Sentence
dataclass
¶
Immutable AST node for a propositional sentence.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
One of ATOM, NEG, CONJ, DISJ, IMPL. |
name |
str | None
|
The atom name (only when type == ATOM). |
sub |
Sentence | None
|
The sub-sentence (only when type == NEG). |
left |
Sentence | None
|
Left operand (only when type in {CONJ, DISJ, IMPL}). |
right |
Sentence | None
|
Right operand (only when type in {CONJ, DISJ, IMPL}). |
Source code in src/pynmms/syntax.py
pynmms.syntax.parse_sentence(s)
¶
Parse a string into a propositional Sentence AST.
Examples:
>>> parse_sentence("A")
Sentence(type='atom', name='A', ...)
>>> parse_sentence("A -> B")
Sentence(type='impl', ..., left=Sentence(type='atom', name='A', ...),
right=Sentence(type='atom', name='B', ...))
Raises:
| Type | Description |
|---|---|
ValueError
|
on empty input, a dangling connective, or a malformed atom. |
Source code in src/pynmms/syntax.py
pynmms.syntax.is_atomic(s)
¶
Return True if s parses to a bare atom (no logical connectives).
Raises ValueError if s does not parse at all (e.g. a malformed atom).