96 lines
2.0 KiB
Go
96 lines
2.0 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"logik/aussagenlogik/rekursion"
|
||
|
"logik/aussagenlogik/schema"
|
||
|
"logik/aussagenlogik/syntaxbaum"
|
||
|
env "logik/core/environment"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/lithammer/dedent"
|
||
|
)
|
||
|
|
||
|
var DATA_ENV string = "data.env"
|
||
|
|
||
|
type dataType struct {
|
||
|
expr string
|
||
|
interpretation []string
|
||
|
}
|
||
|
|
||
|
type resultsType struct {
|
||
|
eval int
|
||
|
atoms []string
|
||
|
depth int
|
||
|
length int
|
||
|
nParentheses int
|
||
|
}
|
||
|
|
||
|
var data dataType
|
||
|
|
||
|
func main() {
|
||
|
// Extrahiere Daten
|
||
|
err := getData()
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
// Ausdruck -> Syntaxbaum
|
||
|
tree, err := schema.ParseExpr(data.expr)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
// Methoden ausführen:
|
||
|
results := resultsType{
|
||
|
eval: rekursion.RekursivEval(tree, data.interpretation),
|
||
|
atoms: rekursion.RekursivAtoms(tree),
|
||
|
depth: rekursion.RekursivDepth(tree),
|
||
|
length: rekursion.RekursivLength(tree),
|
||
|
nParentheses: rekursion.RekursivParentheses(tree),
|
||
|
}
|
||
|
// Resultate anzeigen:
|
||
|
displayResults(tree, results)
|
||
|
}
|
||
|
|
||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
// SONSTIGE METHODEN
|
||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
|
||
|
func getData() error {
|
||
|
env.ENV_FILE_NAME = DATA_ENV
|
||
|
data.expr = env.ReadEnvKey("expr")
|
||
|
s := env.ReadEnvKey("interpretation")
|
||
|
err := json.Unmarshal([]byte(s), &data.interpretation)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func displayResults(tree syntaxbaum.SyntaxBaum, results resultsType) {
|
||
|
fmt.Println(fmt.Sprintf(
|
||
|
dedent.Dedent(`
|
||
|
Syntaxbaum von
|
||
|
F := %[1]s:
|
||
|
|
||
|
%[2]s
|
||
|
|
||
|
Für I = {%[3]s} und F wie oben gilt
|
||
|
eval(F, I) = %[4]d;
|
||
|
atoms(F) = {%[5]s}; <- *
|
||
|
depth(F) = %[6]d; <- *
|
||
|
length(F) = %[7]d; <- *
|
||
|
#parentheses(F) = %[8]d; <- *
|
||
|
|
||
|
* noch nicht implementiert!
|
||
|
Challenge: schreibe diese Methoden! (siehe README.md)
|
||
|
`),
|
||
|
tree.Expr,
|
||
|
tree.Pretty(" "),
|
||
|
strings.Join(data.interpretation, ", "),
|
||
|
results.eval,
|
||
|
// string(results.atoms),
|
||
|
strings.Join(results.atoms, ", "),
|
||
|
results.depth,
|
||
|
results.length,
|
||
|
results.nParentheses,
|
||
|
))
|
||
|
}
|