C not LALR(1) & compiler bugs

stephen at datacube.UUCP stephen at datacube.UUCP
Tue Jan 28 01:39:00 AEST 1986


> C's grammar is CONTEXT SENSITIVE !?    Can it be ?! ...

C is context sensitive in many ways, but so is just about every other
programming language in existence. PASCAL or MODULA-II, for example,
have an ambiguity for:

Statement ::= assign_stmt | procedure_invocation | ...

assign_stmt ::= IDENTIFIER ':=' expression
procedure_invocation ::= IDENTIFIER ...

This also must be resolved by feedback to the lexer.

In a general sense, any programming language where variables are
declared is context-sensitive, since the semantics of later invocations
of the variable depend on what type the variable was declared.

Really, you are flaming the lack of power of an LALR(n) grammar. However,
due to considerations of efficiency and convenience, an LALR grammar is
probably one of the best choices for parsing a language (especially if
you have yacc available).



More information about the Comp.lang.c mailing list