Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyNotFoundException #8

Open
nojaf opened this issue Jun 29, 2019 · 3 comments
Open

KeyNotFoundException #8

nojaf opened this issue Jun 29, 2019 · 3 comments

Comments

@nojaf
Copy link

nojaf commented Jun 29, 2019

Hi, I'm trying out this library and it would be nice if I could do the following:

open Proviant

let expression = "INTERACTIVE || (FOO && BAR) || BUZZ"
let expr = BooleanAlgebraExpression(expression)

expr.GenerateTruthTable()
let result = expr.Evaluate()

However when executing GenerateTruthTable or Evaluate I get a System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. exception.

How should my expression syntax be looking in this case?

@Genfood
Copy link
Owner

Genfood commented Jun 29, 2019

Hey,

first of all, which language are you using? :)

If you like to create a truth table try to use variables like 'a', 'b', 'c', ... instead of INTERACTIVE, foo or bar.
And it is only necessary to call:

let truthTable = expr.GenerateTruthTable()

If you like to evaluate a finished expression like false || true you could use

let result = expr.Evaluate()

I will add a sample Project using C# so you could take a look at it.

And its important that u add a space between every token, also between the brackets:
let expression = "INTERACTIVE || ( FOO && BAR ) || BUZZ"

@nojaf
Copy link
Author

nojaf commented Jun 29, 2019

I'm using F# here, but that shouldn't really matter.
Trying let expression = "a | ( b && c ) | d" works, however, it is unfortunate that I have to modify my original expression.
Could the parsing engine by improved for this scenario?

@Genfood
Copy link
Owner

Genfood commented Jun 29, 2019

No that shouldn't matter. :)

You are right, that could be annoying.
So far I always pre checked if the expression matched this pattern.
I will take a quick look, I think it shouldn't be that hard to allow all kind of placeholders instead of just the alphabet.

But the spaces are necessary so far, but I will do some brainstorming for a normalization...

Genfood added a commit that referenced this issue Jun 29, 2019
- Added the possibility to use any kind of Variables for a truth table not just the alphabet.
- Changed the way the normalization works because it could lead to some errors.

TODO:
- Still needs spaces between every token.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants