Is right recursive C grammar necessary?

Steven Ryan smryan at garth.UUCP
Thu Jun 16 06:57:27 AEST 1988


In article <428 at erc3ba.UUCP> rsc at erc3ba.UUCP (Rich Chomiczewski) writes:
>Is this right recursive grammar required by the ANSI C committee?
>Can the above rule be written left recursive and still conform
>to the ANSI C standard?

A left recursive grammar can be automatically transformed into right recursive
grammar and vice versa--the defined language remains context-free or regular.

Right recursive or Griebach form is useful for writing a recursive-descent
parser or using an LL(k) parse generator. Left or right recursive can be
used for xxLR(k).

The production was probably right recursive to ensure storage-class-specifiers
precede the type-specifier (I don't know what the entire grammar is). A left
recursive rule would require two productions.

A -> xA  |  y

would produce the same language as

A -> A' y
A' -> A'x  | null

sm ryan
april come she will/may she will stay/june she'll change her tune/
july she will fly/august die she must/september i'll remember.



More information about the Comp.lang.c mailing list