Search code examples
cgrammarbnf

Is this C BNF grammar incomplete?


I often see this C grammar in books. However it seems <identifier> is never declared.

Am I missing something or is this grammar incomplete?


Solution

  • I can't speak for whether the grammar is complete, but <identifier> is a token (i.e. a terminal), in the same way as e.g. <string> and many others are.

    Tokens are not defined in the grammar itself but rather in a lexer specification.

    The lexer is a component of most parser systems, which reads the raw input and turns it into a stream of higher level tokens (a.k.a. lexemes) that the parser then consumes.