Browse Source

master > master: codego - generics

master
RD 1 year ago
parent
commit
0856bfc0b0
  1. 3
      codego/aussagenlogik/formulae/formulae_basic.go
  2. 14
      codego/aussagenlogik/formulae/formulae_construction.go
  3. 25
      codego/aussagenlogik/schema/schema.go

3
codego/aussagenlogik/formulae/formulae_basic.go

@ -11,6 +11,7 @@ import (
type Formula struct {
kind string
name string
expr string
valence int
subformulae [](*Formula)
@ -28,6 +29,8 @@ func (fml *Formula) SetExpr(expr string) { fml.expr = expr }
func (fml Formula) GetExpr() string { return fml.expr }
func (fml Formula) GetName() string { return fml.name }
func (fml *Formula) SetSubformulae(subfmls [](*Formula)) {
fml.subformulae = subfmls
fml.valence = len(subfmls)

14
codego/aussagenlogik/formulae/formulae_construction.go

@ -22,23 +22,25 @@ var Contradiction = Formula{
* METHODS: Constructions
* ---------------------------------------------------------------- */
func Atom(expr string) Formula {
func Atom(name string) Formula {
return Formula{
kind: "atom",
expr: expr,
name: name,
expr: name,
valence: 0,
subformulae: [](*Formula){},
}
}
func NegatedAtom(expr string) Formula {
return Negation(Atom(expr))
func NegatedAtom(name string) Formula {
return Negation(Atom(name))
}
func Generic(expr string) Formula {
func Generic(name string) Formula {
return Formula{
kind: "generic",
expr: expr,
name: name,
expr: "{" + name + "}",
valence: 0,
subformulae: [](*Formula){},
}

25
codego/aussagenlogik/schema/schema.go

@ -3,6 +3,7 @@ package schema
import (
"logik/aussagenlogik/formulae"
parser "logik/grammars/aussagenlogik"
"regexp"
"github.com/antlr/antlr4/runtime/Go/antlr"
)
@ -65,22 +66,13 @@ func (ant antlrTree) getLabel() string {
}
func (ant antlrTree) getTextContent() string {
var expr string = ant.getLabel()
for _, subant := range ant.getChildren() {
expr += subant.getTextContent()
}
return expr
}
func (ant antlrTree) getTextContentLeaves() string {
var expr string = ""
var subants = ant.getChildren()
if len(subants) == 0 {
expr = ant.getLabel()
} else {
for _, subant := range subants {
expr += subant.getTextContent()
}
return ant.getLabel()
}
for _, subant := range subants {
expr += subant.getTextContent()
}
return expr
}
@ -116,9 +108,12 @@ func (ant antlrTree) toFormula() formulae.Formula {
case "contradiction":
return formulae.Contradiction
case "atom":
return formulae.Atom(ant.getTextContentLeaves())
name := ant.getTextContent()
return formulae.Atom(name)
case "generic":
return formulae.Generic(ant.getTextContentLeaves())
re := regexp.MustCompile(`^{|}$`)
name := string(re.ReplaceAll([]byte(ant.getTextContent()), []byte("")))
return formulae.Generic(name)
case "not":
// NOTE: expr = ! expr
if nChildren == 2 {

Loading…
Cancel
Save