title: How to list all expressions in Python PLY
body: <p>I'm using PLY and have written below expressions to match this kind of sample string '(A OR B OR C)'.</p>
  
  <blockquote>
  <pre><code>expression : LPAREN KEYWORD AND KEYWORD RPAREN
             | LPAREN KEYWORD OR KEYWORD RPAREN
             | LPAREN KEYWORD AND KEYWORD AND KEYWORD RPAREN
             | LPAREN KEYWORD OR KEYWORD OR KEYWORD RPAREN
             | LPAREN KEYWORD AND KEYWORD AND KEYWORD AND KEYWORD RPAREN
             | LPAREN KEYWORD OR KEYWORD OR KEYWORD OR KEYWORD RPAREN
             | LPAREN KEYWORD AND KEYWORD AND KEYWORD AND KEYWORD AND KEYWORD RPAREN
             | LPAREN KEYWORD OR KEYWORD OR KEYWORD OR KEYWORD OR KEYWORD RPAREN
             | LPAREN KEYWORD AND KEYWORD AND KEYWORD AND KEYWORD AND KEYWORD AND KEYWORD RPAREN
             | LPAREN KEYWORD OR KEYWORD OR KEYWORD OR KEYWORD OR KEYWORD OR KEYWORD RPAREN
  </code></pre>
  </blockquote>
  
  <p>I have no idea how to cover all cases so I have to list them as many as possible and I know that's not elegant.</p>
  
  <p>Any ideas to optimize this expression? Thanks a lot.</p>