Browse Source

master > master: codego main aufgeräumt

master
RD 1 year ago
parent
commit
8778d31676
  1. 49
      codego/main.go

49
codego/main.go

@ -1,12 +1,12 @@
package main
import (
"encoding/json"
"fmt"
"logik/aussagenlogik/rekursion"
"logik/aussagenlogik/schema"
"logik/aussagenlogik/syntaxbaum"
env "logik/core/environment"
"logik/core/utils"
"strings"
"github.com/lithammer/dedent"
@ -31,23 +31,10 @@ var data dataType
func main() {
// Extrahiere Daten
err := getData()
if err != nil {
return
}
getData()
// 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),
}
tree := schema.ParseExpr(data.expr)
results := getResults(tree)
// Resultate anzeigen:
displayResults(tree, results)
}
@ -56,12 +43,32 @@ func main() {
// SONSTIGE METHODEN
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
func getData() error {
func getData() {
env.ENV_FILE_NAME = DATA_ENV
data.expr = env.ReadEnvKey("expr")
s := env.ReadEnvKey("interpretation")
err := json.Unmarshal([]byte(s), &data.interpretation)
return err
utils.JsonToArrayOfStrings(s, &data.interpretation)
}
func getResults(tree syntaxbaum.SyntaxBaum) resultsType {
ch1 := make(chan int)
ch2 := make(chan []string)
ch3 := make(chan int)
ch4 := make(chan int)
ch5 := make(chan int)
go rekursion.RekursivEval(ch1, tree, data.interpretation)
go rekursion.RekursivAtoms(ch2, tree)
go rekursion.RekursivDepth(ch3, tree)
go rekursion.RekursivLength(ch4, tree)
go rekursion.RekursivParentheses(ch5, tree)
// Methoden ausführen:
return resultsType{
eval: <-ch1,
atoms: <-ch2,
depth: <-ch3,
length: <-ch4,
nParentheses: <-ch5,
}
}
func displayResults(tree syntaxbaum.SyntaxBaum, results resultsType) {
@ -82,7 +89,7 @@ func displayResults(tree syntaxbaum.SyntaxBaum, results resultsType) {
* noch nicht implementiert!
Challenge: schreibe diese Methoden! (siehe README.md)
`),
tree.Expr,
tree.GetExpr(),
tree.Pretty(" "),
strings.Join(data.interpretation, ", "),
results.eval,

Loading…
Cancel
Save