Why is the seq declaration in the C ++ standard written like this?

declaration-seq:
   declaration
   declaration-seq declaration

not this way:

declaration-seq:
   declaration
   declaration declaration-seq

Are these two definitions interchangeable? What is the difference between the two?

+6
source share
1 answer

This is the remainder of the legacy of C ++ C. The C-grammar is (almost) LALR (1) and therefore uses left recursion as much as possible. The C ++ grammar no longer confuses LALR, but many of the rules are still written in the form that the LALR parser prefers because there is no reason to change them - any parsing algorithm powerful enough to handle C ++ does not care what type syntax recursion is used.

+6

Source: https://habr.com/ru/post/1016935/


All Articles