Search code examples
pythonparsingyaccplylalr

Is possible to print all the posibilities of an expression like (x AND ( y OR z)) with yacc?


I'm trying to print all the possibilities of a complex logical expresion of the form ((a AND (b OR c OR d)) AND e AND (f OR g)). For example the output should be

a, b, e, f
a, c, e, f
a, d, e, f
a, b, e, g
a, c, e, g
a, d, e, g

etc,

I'm using a parser (PLY for python), it uses the LARL algorithm but I don't know if it is the proper way to solve this kind of problem.

I can't find a way to print the all the possibilities in the right way, so I was thinking that maybe PLY it is not the right tool for this task.

Do you recommend me to code my own parser to solve this kind of problem?


Solution

  • I recommend that you process the resulting parse tree as required by your application. A parser is merely a front-end that returns a syntactic organization according to the action rules you give it; it does not magically complete your application.

    You still have coding to do: you need to traverse the resulting data structure (under your control) and provide either all of the child possibilities (AND node) or any positive quantity of the possibilities (OR node) for the expression you've parsed.