Precedence Question - (nf)

pedz at smu.UUCP pedz at smu.UUCP
Wed Feb 22 19:23:06 AEST 1984

smu!pedz    Feb 21 21:58:00 1984

You people must take me for a complete fool.  The responses I have
received are mostly stupid and unqualified.  The reponses 1 and 2
listed above are a good example of people talking about subjects which
they know nothing about.  The response 3 above is more reasonable
however he seems to have forgotten the original question.  The fact
that the assign between the ? and the : is the one in question, not
the first (left hand) assignement which is not even part of the real

I realize that an assignment results in a value.  If I was this
dumb do you think I would have posed the problem in the first place?
The fact that precedence of the assignement operator is lower than the
precedence of the ?: operator results in the original expressing being
incorrect (illegal).  The fellow in a note futher down in this file
agrees with me.  The reason I now say that the expression is illegal
is because of all of the weak arguments I have heard to the contrary.
Arguements such as, "the colon is not an operator",  "precedence is
needed only for ambiquities", "precedence has nothing to do with the
order of evaluation", "precedence has nothing to do with legal
syntax", etc.

It is obvious to me that my respondants are far less knowledgable than
I about the subject.  So I will tell you the root of the problem and
why the other fellow's compiler decides the expression is illegal but
the Vax compiler does not.

It all has to do with the machine used for parsing.  The Vax compiler
(I am assuming) is a product of yacc and is thus an LALR compiler.  I
wrote some input to yacc to simulate this part of the C syntax and it
produced a parser which also accepted the syntax.  The problem is that
there is no way to tell yacc about ternary operators in a way which it
fully understands.  The other fellow's compiler is a recursive descent
compiler (again I am assuming).  (Are you following all of this?)
With a recursive descent compiler it would be impossible (unless you
really tried) to make a parser which would accept the syntax in
question by accident.

Thus it all comes down to the fact that one method of generating a
compiler yields a parser which accepts the syntax unless the designer
specifically avoids the problem and another method which yields a
parser which does not accept the syntax unless the designer
specifically wants it.

I hope you appreciate me taking the time to tell all of you people
this little story about compilers and the world of parsers.  I has
been a real drag for me.

Please flame, respond, curse, etc via mail since I have given up
reading these notes for lack of intellectual stimulation.


More information about the Comp.lang.c mailing list