Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

declaration-seq:
   declaration
   declaration-seq declaration

not this way:

declaration-seq:
   declaration
   declaration declaration-seq

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

like image 563
LearningMath Avatar asked May 02 '17 12:05

LearningMath


1 Answers

This is a vestige of C++'s C heritage. The C grammar is (almost) LALR(1), and therefore uses left recursion as much as possible. The C++ grammar is not even vaguely LALR anymore, but many of the rules are still written in the form an LALR parser would prefer, because there's no reason to change them—any parser algorithm powerful enough to handle C++ doesn't care which type of syntactic recursion is used.

like image 146
zwol Avatar answered Nov 04 '22 16:11

zwol