master > master: codego Aufräumung von SyntaxBaum Methoden

This commit is contained in:
RD
2021-05-12 18:45:18 +02:00
parent 100701d610
commit 5e89d57dad
2 changed files with 70 additions and 64 deletions

View File

@@ -7,20 +7,40 @@ import (
)
type SyntaxBaum struct {
Kind string
Expr string
Valence int
Children [](*SyntaxBaum)
kind string
expr string
valence int
children [](*SyntaxBaum)
}
/* ---------------------------------------------------------------- *
* METHODS
* ---------------------------------------------------------------- */
func (tree *SyntaxBaum) SetKind(kind string) {
tree.kind = kind
}
func (tree SyntaxBaum) GetKind() string {
return tree.kind
}
func (tree *SyntaxBaum) SetExpr(expr string) {
tree.expr = expr
}
func (tree SyntaxBaum) GetExpr() string {
return tree.expr
}
func (tree *SyntaxBaum) SetChildren(children [](*SyntaxBaum)) {
tree.children = children
tree.valence = len(children)
}
func (tree SyntaxBaum) GetChildren() []SyntaxBaum {
var n int = tree.Valence
var n int = tree.valence
var children = make([]SyntaxBaum, n)
for i, subtreePtr := range tree.Children {
for i, subtreePtr := range tree.children {
children[i] = *subtreePtr
}
return children
@@ -33,8 +53,8 @@ func (tree SyntaxBaum) GetChild(indexOpt ...int) (SyntaxBaum, error) {
}
var subtree SyntaxBaum
var err error
if 0 <= index && index < tree.Valence {
subtree = *(tree.Children[index])
if 0 <= index && index < tree.valence {
subtree = *(tree.children[index])
} else {
err = errors.New(fmt.Sprintf("Instance has no child of index %d !", index))
}
@@ -51,18 +71,18 @@ func (tree SyntaxBaum) Pretty(preindentOpt ...string) string {
func (tree SyntaxBaum) pretty(preindent string, tab string, prepend string, depth int) string {
var indent string = preindent + strings.Repeat(tab, depth)
switch tree.Valence {
switch tree.valence {
case 0:
switch kind := tree.Kind; kind {
switch kind := tree.kind; kind {
case "atom", "generic":
return indent + prepend + kind + " " + tree.Expr
return indent + prepend + kind + " " + tree.expr
default:
return indent + prepend + kind
}
default:
var lines string = indent + prepend + tree.Kind
var lines string = indent + prepend + tree.kind
prepend = "|__ "
for _, subtree := range tree.Children {
for _, subtree := range tree.children {
lines += "\n" + subtree.pretty(preindent, tab, prepend, depth+1)
}
return lines
@@ -74,11 +94,11 @@ func (tree SyntaxBaum) pretty(preindent string, tab string, prepend string, dept
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
func (tree SyntaxBaum) IsIrreducible() bool {
return tree.Valence == 0
return tree.valence == 0
}
func (tree SyntaxBaum) IsAtom() bool {
return tree.Kind == "atom"
return tree.kind == "atom"
}
func (tree SyntaxBaum) IsLiteral() bool {
@@ -94,41 +114,41 @@ func (tree SyntaxBaum) IsLiteral() bool {
}
func (tree SyntaxBaum) IsGeneric() bool {
return tree.Kind == "generic"
return tree.kind == "generic"
}
func (tree SyntaxBaum) IsTautologySymbol() bool {
return tree.Kind == "taut"
return tree.kind == "taut"
}
func (tree SyntaxBaum) IsContradictionSymbol() bool {
return tree.Kind == "contradiction"
return tree.kind == "contradiction"
}
func (tree SyntaxBaum) IsConnective() bool {
return tree.Valence > 0
return tree.valence > 0
}
func (tree SyntaxBaum) IsNegation() bool {
return tree.Kind == "not"
return tree.kind == "not"
}
func (tree SyntaxBaum) IsConjunction2() bool {
return tree.Kind == "and2"
return tree.kind == "and2"
}
func (tree SyntaxBaum) IsConjunction() bool {
return tree.Kind == "and" || tree.Kind == "and2"
return tree.kind == "and" || tree.kind == "and2"
}
func (tree SyntaxBaum) IsDisjunction2() bool {
return tree.Kind == "or2"
return tree.kind == "or2"
}
func (tree SyntaxBaum) IsDisjunction() bool {
return tree.Kind == "or" || tree.Kind == "or2"
return tree.kind == "or" || tree.kind == "or2"
}
func (tree SyntaxBaum) IsImplication() bool {
return tree.Kind == "implies"
return tree.kind == "implies"
}