How would one compare two parse tree to find ambiguity in a Context Free Grammar by using Z3 solver? -


example grammar:

e ::= e + e | n 

i need prove grammar ambiguous due following 2 paths:

e -> e + e -> e + e + e -> n + e + e e -> e + e -> n + e -> n + e + e 

the idea 1 compare functions "sets" symbol1(symbol,index,time) (for specific time t) , symbol2(symbol,index,time) - finding equivalent - having different predecessor (i.e @ time t-1)

the problem have no idea how compare 2 functions symbol1 , symbol2

i can post code, if you're interested .... (its page , half worth, might inappropriately long?).

the code written in z3py.

checking whether cfg ambiguous undecidable in general. however, if restrict number of rule applications small number, can try generating possible strings many applications , check whether can reach same string using different number of steps. in case, don't think smt solvers fit kind of problem since number of strings derivable can grow exponentially number of steps; require keep number of steps small number, making problem uninteresting.

of course, if know property of grammar in advance, can come custom algorithm take advantage of it. (say if it's lalr(1) parseable.) in case other algorithmic methods better compared smt based solution.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -