Given the following grammar:
BoolExpr ::= BoolConj { "or" BoolConj }.
BoolConj ::= BoolLit { "and" BoolLit }.
BoolLit ::= [ "not" ] BoolPosLit.
BoolPosLit ::= "true"| "false"| "(" BoolExpr ")".
I want to write a DCG parser for the grammar above. The parser simply only have to accepts (succeeds) or rejects (fails) on a given input,
Here is what I have:
boolepxr([or(O)|BoolExpr]) -->
['or'],
boolconj(O),
boolexpr(BoolExpr).
boolconj([and(A)|BoolConj]) -->
['and'],
boollit(A),
boolconj(BoolConj).
boollit([not(N)|BoolLit]) -->
['not'],
boolps(N).
boolps([true(B)|BoolPs]) -->
['true'],
boolexpr(B),
boolps(BoolPS).
boolps([false(B)|BoolPs]) -->
['false'],
boolexpr(B),
boolps(BoolPS).
However, when I run this program, I didn't get the appropriate output.