grammar

Why can't C++ be parsed with a LR(1) parser?

我的梦境 提交于 2019-11-25 23:58:25
问题 I was reading about parsers and parser generators and found this statement in wikipedia\'s LR parsing -page: Many programming languages can be parsed using some variation of an LR parser. One notable exception is C++. Why is it so? What particular property of C++ causes it to be impossible to parse with LR parsers? Using google, I only found that C can be perfectly parsed with LR(1) but C++ requires LR(∞). 回答1: There is an interesting thread on Lambda the Ultimate that discusses the LALR

Is C++ context-free or context-sensitive?

纵饮孤独 提交于 2019-11-25 20:03:01
I often hear claims that C++ is a context-sensitive language. Take the following example: a b(c); Is this a variable definition or a function declaration? That depends on the meaning of the symbol c . If c is a variable , then a b(c); defines a variable named b of type a . It is directly initialized with c . But if c is a type , then a b(c); declares a function named b that takes a c and returns an a . If you look up the definition of context-free languages, it will basically tell you that all grammar rules must have left-hand sides that consist of exactly one non-terminal symbol. Context