master > master: allgemeine Aufräumung
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from __future__ import annotations;
|
||||
# install: lark; lark-parser; lark-parser[regex].
|
||||
# https://lark-parser.readthedocs.io/en/latest/grammar.html
|
||||
from lark import Lark;
|
||||
|
||||
from aussagenlogik.syntaxbaum import SyntaxBaum;
|
||||
@@ -16,10 +14,10 @@ from aussagenlogik.syntaxbaum import SyntaxBaum;
|
||||
# GLOBALE KONSTANTEN
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
## lexer
|
||||
with open('aussagenlogik/grammar.lark', 'r') as fp:
|
||||
# lexer durch LARK erzeugen
|
||||
with open('grammars/grammar.lark', 'r') as fp:
|
||||
grammar = ''.join(fp.readlines());
|
||||
lexerAussagenlogik = Lark(grammar, start='expr', regex=True);
|
||||
lexer = Lark(grammar, start='expr', regex=True);
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# METHODE: string -> Syntaxbaum
|
||||
@@ -27,43 +25,6 @@ with open('aussagenlogik/grammar.lark', 'r') as fp:
|
||||
|
||||
def stringToSyntaxbaum(expr: str) -> SyntaxBaum:
|
||||
try:
|
||||
return SyntaxBaum(lexerAussagenlogik.parse(expr));
|
||||
return SyntaxBaum(lexer.parse(expr));
|
||||
except:
|
||||
raise Exception('Ausdruck \033[1m{}\033[0m konnte nicht erkannt werden!'.format(expr));
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# METHODEN: Erkennung von Formeltypen
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def isAtom(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind == 'atom';
|
||||
|
||||
def isLiteral(fml: SyntaxBaum) -> bool:
|
||||
return isAtom(fml) or (isNegation(fml) and isAtom(fml.child));
|
||||
|
||||
def isBeliebig(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind == 'beliebig';
|
||||
|
||||
def isTrueSymbol(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind == 'taut';
|
||||
|
||||
def isFalseSymbol(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind == 'kontr';
|
||||
|
||||
def isNegation(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind == 'neg';
|
||||
|
||||
def isConjunction(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind == 'konj';
|
||||
|
||||
def isLongConjunction(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind in ['konj', 'konj_lang'];
|
||||
|
||||
def isDisjunction(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind == 'disj';
|
||||
|
||||
def isLongDisjunction(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind in ['disj', 'disj_lang'];
|
||||
|
||||
def isImplication(fml: SyntaxBaum) -> bool:
|
||||
return fml.kind == 'impl';
|
||||
|
||||
Reference in New Issue
Block a user