Skip to content
/ vera Public

Logical expression parser and CLI truth table generator

License

Notifications You must be signed in to change notification settings

Ro5bert/vera

Repository files navigation

vera

Installation

go get https://github.com/Ro5bert/vera

The CLI binary can be built from the cli folder; for example:

cd $(go env GOPATH)/src/github.com/Ro5bert/vera/cli && go build -o vera main.go

Syntax

0 False
1 True
a-z, A-Z Statement
(...) Grouping/explicit binary operator precedence
! Negate
& AND
| OR
^ XOR
> Conditional/Implication
= Bi-conditional/Equality/IFF

Limitations

  • There is a maximum of 52 atomic statements (26 lowercase letters + 26 uppercase letter = 52). (Although, I am not sure why or how you would have 52 atomic statements... performance is O(2n) where n is number of atomic statements).
  • To avoid subjectivity in operator precedence, all binary operators are assigned equal precedence and must be parenthesized as necessary (even if the operators are all AND, for example); this may change in the future. (Negation, of course, still has higher precedence than all binary operators.)

Sample CLI Output

Sample CLI Output

Use as a Library Example

// Assuming "github.com/Ro5bert/vera" is imported

stmt, truth, err := vera.Parse("a > b")
if err != nil {
    // handle error
}
// Iterate over all sets of truth values and print out the stmt evaluated at each set:
for ; truth.Val < (1 << len(truth.Names)); truth.Val++ {
    fmt.Println(stmt.Eval(truth))
}

About

Logical expression parser and CLI truth table generator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages