c - Does there exist an LR(k) grammar with no LL(1) equivalent -
i haven't been able find answer yet. there grammars context free , non-ambiguous can't converted ll(1)?
i found 1 production couldn't figure out how convert ll(1): parameter-type-list
production in c99:
parameter-type-list: parameter-list parameter-list , ...
is example of lr(k) grammar doesn't have ll(1) equivalent or doing wrong?
edit: copied wrong name, meant copy parameter-declaration:
parameter-declaration: declaration-specifiers declarator declaration-specifiers abstract-declarator(opt)
the problem declarator , abstract declarator both having ( in first set, being left recursive.
in general, lr(k)
grammars more powerful ll(k)
. means there languages lr(k)
parser, not ll(k)
.
one of examples language defined grammar:
s -> s s -> p p -> p b p -> \epsilon
or, in other words, string of a
's, followed same or less number of b
's. follows fact ll(k)
parser must make decision every a
encountered - paired b
- looking ahead no more k
symbols of input, can a
's, giving no useful information. strict proof, @ second part of accepted answer here https://cs.stackexchange.com/questions/3350/is-this-language-ll1-parseable
your example, however, can left factored in ll(1) grammar be
parameter-type-list -> parameter-list optional-ellipsis optional-ellipsis -> \epsilon optional-ellipsis -> , ...
one note follow
set parameter-list
contain ,
character, , can cause first-follow
conflict. if case, need see parameter-list
definition fix conflict too.
edit: parameter-declaration
rule seems complicated answer right away. can try perform left factorization hands conflicting alternatives, or assistance tool, antlr.
Comments
Post a Comment