Path: utzoo!attcan!uunet!husc6!bloom-beacon!bu-cs!purdue!decwrl!labrea!sri-unix!garth!smryan From: smryan@garth.UUCP (Steven Ryan) Newsgroups: comp.lang.c Subject: Re: Is right recursive C grammar necessary? Message-ID: <746@garth.UUCP> Date: 16 Jun 88 19:36:29 GMT References: <428@erc3ba.UUCP> <433@dmk3b1.UUCP> Reply-To: smryan@garth.UUCP (Steven Ryan) Organization: INTERGRAPH (APD) -- Palo Alto, CA Lines: 23 In article <433@dmk3b1.UUCP> dmk@dmk3b1.UUCP (David Keaton) writes: > No, and in fact if you're using yacc you want left recursion >instead, wherever reasonable. This is because the yacc-generated parser >has to keep all the states around until the appropriate rules get >reduced, and with right recursion this can make the stack get huge. This depends on how much memory you have. On VM it shouldn't matter, unless YACC is incredibly stupid and Fortranish by using a fixed size stack. You shouldn't have to stand a grammar on its head for anything advertised as an LR(1) parse generator. > If you were using a recursive descent parser or an LL(1) parser, >then you would use right recursion to avoid ambiguity. Not ambiguity, but infinite recursion if you're not careful. An LL(k) parser needs to know the first k terminals of each production: A -> A b. You need the first k terminals of A b which needs the first k terminals of A which needs the first k terminals of A b which needs the first k terminals ... This is not an ambiguity, but it does require cleverness. Or right recursion.