Package ExprRules - defining a grammar by referencing a vector

I am trying to define a boolean expression grammar which has changing rules. I would like to reference a vector of strings, to then change certain production rules of the grammar.
The following minimal working example is how the examples provided by the package suggest one defines a grammar:

using ExprRules
using ExprOptimization

grammarExample = @grammar begin
    bexp = (bexp)                    
    bexp = !bexp                     
    bexp = bexp && bexp              
    bexp = bexp || bexp                
    bexp = true      
    bexp = false  
    bexp = |(a,b,c) 
end

S = SymbolTable(grammarExample)

tree = RuleNode(3, [RuleNode(7), RuleNode(8)])
ex = get_executable(tree, grammarExample)
S[:a] = true
S[:b] = true
Core.eval(S, ex)

I would like to do the following:

using ExprRules
using ExprOptimization

vect = ["a","b","c"]

grammarExample = @grammar begin
    bexp = (bexp)                    
    bexp = !bexp                     
    bexp = bexp && bexp              
    bexp = bexp || bexp                
    bexp = true      
    bexp = false  
    bexp = |(vect[:])  
end

S = SymbolTable(grammarExample)

tree = RuleNode(3, [RuleNode(7), RuleNode(8)])
ex = get_executable(tree, grammarExample)
S[:a] = true
S[:b] = true
Core.eval(S, ex)

The resulting grammar and the SymbolTable seem to be the same in both cases, but the Core.eval(S, ex) gives the following error:

LoadError: TypeError: non-boolean (String) used in boolean context
Stacktrace:
 [1] interpret(tab::Dict{Symbol, Any}, ex::Expr)
   @ ExprRules.Interpreter ~/.julia/packages/ExprRules/uZyj0/src/interpreter.jl:62
 [2] eval(tab::Dict{Symbol, Any}, ex::Expr)
   @ ExprRules ~/.julia/packages/ExprRules/uZyj0/src/ExprRules.jl:417

@grammar need Symbol not String

julia> using ExprRules

julia> grammarExample0 = @grammar begin
           bexp = (bexp)
           bexp = !bexp
           bexp = bexp && bexp
           bexp = bexp || bexp
           bexp = true
           bexp = false
           bexp = |(a,b,c)
       end
1: bexp = bexp
2: bexp = !bexp
3: bexp = bexp && bexp
4: bexp = bexp || bexp
5: bexp = true
6: bexp = false
7: bexp = a
8: bexp = b
9: bexp = c


julia> grammarExample0.rules
9-element Vector{Any}:
      :bexp
      :(!bexp)
      :(bexp && bexp)
      :(bexp || bexp)
  true
 false
      :a
      :b
      :c

julia> vect = ["a","b","c"]
3-element Vector{String}:
 "a"
 "b"
 "c"

julia>

julia> grammarExample = @grammar begin
           bexp = (bexp)
           bexp = !bexp
           bexp = bexp && bexp
           bexp = bexp || bexp
           bexp = true
           bexp = false
           bexp = |(vect[:])
       end
1: bexp = bexp
2: bexp = !bexp
3: bexp = bexp && bexp
4: bexp = bexp || bexp
5: bexp = true
6: bexp = false
7: bexp = a
8: bexp = b
9: bexp = c


julia> grammarExample.rules
9-element Vector{Any}:
      :bexp
      :(!bexp)
      :(bexp && bexp)
      :(bexp || bexp)
  true
 false
      "a"
      "b"
      "c"

- vect = ["a","b","c"]
+ vect = [:a, :b, :c]

grammarExample = @grammar begin
    bexp = (bexp)                    
    bexp = !bexp                     
    bexp = bexp && bexp              
    bexp = bexp || bexp                
    bexp = true      
    bexp = false  
    bexp = |(vect[:])  
end
1 Like

Thank you :relaxed: