I know that it's possible to build an LL(1) parser for the Dyck language, i.e. a balanced string of parentheses, so the Dyck language is a deterministic context-free language.
But what's an example of a deterministic context-free grammar that matches this language? I'm finding it surprisingly hard to construct one.
According to here and here, a DCFG is a CFG where for each non-terminal, the production rules do not share the same prefix of non-terminals.
The common way of matching the Dyck language with a CFG is this (e
is $\epsilon$):
S -> (S)S | e
This is not a DCFG because the two production rules share the same prefix of non-terminals, which is the empty string. I'm having a hard time modifying this so that there is no common prefix. The best I was able to achieve is this:
A -> (BA | $
B -> ) | (BB
This generates balanced parenthesis followed by the symbol $
. If you insist that there be no ending $
, is the language suddenly not deterministic anymore??