Is the Python's grammar LL(1)?

前端 未结 2 1037
猫巷女王i
猫巷女王i 2020-12-18 04:02

Possible duplicate for this question however for me it\'s not specific enough.

The python grammar is claimed to be LL(1), but I\'ve noticed some expressions in the P

2条回答
  •  轮回少年
    2020-12-18 04:52

    You're correct that constructs like 'is' | 'is' 'not' aren't LL(1). They can be left-factored to LL(1) quite easily by changing it to 'is' notOpt where notOpt: 'not' | ϵ or, if you allow EBNF syntax, just 'is' 'not'? (or 'is' ['not'] depending on the flavor of EBNF).

    So the language is LL(1), but the grammar technically is not. I assume the Python designers decided that this was okay because the left-factored version would be more difficult to read without much benefit and the current version can still be used as the basis for an LL(1) parser without much difficulty.

提交回复
热议问题