Thedefinition in textbook:
Thefirst letter, L for left to right or R for right to left, denotes the order inwhich to scan the source text.
Thesecond letter denotes the derivation of the constructed parse tree. At eachstep in a left (L) derivation of a parse tree, the leftmost non-terminal in thetree is replaced by a terminal. In a right (R) derivation, the rightmostnon-terminal is replaced. Top-down parses that scan input from left to rightproducing a left derivation. Bottom up parses that scan the symbols left toright produces a right derivation.
Thek denotes the number of lookahead symbols needed by the parser. With k = 1,only the next symbol is needed.
Additional comprehension:
Those are the correcttechnical definitions. In practice LL(k) means you are building arecursive-descent parser. Recursive-descent parsers have a method for each rulein the grammar and proceed are predictive in that each rule has to predictwhich alternative will match. The parse proceeds from a start symbol and routesdown into the various other rules depending on the lookahead. LL(k) implies upto k symbols of lookahead are visible to the parser for some fixed integer k.[Note that syntactic predicates allow you to effectively modulate k from onesymbol to the entire rest of the input.]
Check out a simple LL(1) rule:
a : A
| B
;
Here, rule 'a' (or method a()) must guess whichalternative will be succesful. Using the lookahead (which will be either A orB), it decides.
a() {
if ( lookahead==A ) { match(A); }
else { match(B); }
}
LL(1) parsers may be generalized to LL(k) for k>1. Forexample, the following grammar is nondeterministic upon token A:
a -> A B C
a -> A D E
where A, B, C, D, and E are some vocabularytokens. Because both productions have a common prefix of A, an LL(1) parsercould not determine which production was going to successfully match. However,if the parser could see ahead to both the A and what followed A on the inputstream, the parser could determine which production was going to match. AnLL(2) parser is such a creature; hence, rule a is unambiguous in the LL(2)sense. A grammar for which a deterministic LL(k) parser can be built is LL(k).A language for which an LL(k) grammar exists is LL(k).