ll(k)

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).


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值