ambiguous why?

Alan J Rosenthal flaps at dgp.toronto.edu
Fri Apr 8 12:43:47 AEST 1988


Eddie Wyatt and Rich Salz both write that i+=*p shouldn't be ambiguous
because there is a rule that says that the lexer should always take the
longest possible token.

However, I think they are confusing different kinds of ambiguity.  :-)
One is an ambiguity between interpretations of expressions given a
certain set of rules, and the other is an ambiguity between deciding
which set of rules to use.

When scanning `+=*', older compilers would ALWAYS take the token list
to be `+' and `=*'.  Newer compilers, based on the rule that the
scanner should always take the longest possible token, would ALWAYS
take the token list to be `+=' and `*'.[1]  If you're writing a
compiler which is supposed to act correctly in either circumstance,
this code is ambiguous.

ajr

--

[1] In effect.

-- 
"Comment, Spock?"
"Very bad poetry, Captain."




More information about the Comp.lang.c mailing list