Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!blandy From: blandy@marduk.cs.cornell.edu (Jim Blandy) Newsgroups: comp.lang.c Subject: Re: Are yacc parsers portable ? Message-ID: <19813@cornell.UUCP> Date: 30 Jul 88 19:03:05 GMT References: <3950010@eecs.nwu.edu> Sender: nobody@cornell.UUCP Reply-To: blandy@cs.cornell.edu (Jim Blandy) Organization: Cornell Univ. CS Dept, Ithaca NY Lines: 35 In article <3950010@eecs.nwu.edu> naim@eecs.nwu.edu (Naim Abdullah) writes: >Is the C parser produced by yacc, portable ? I was looking at it and it had >stuff like: ... > short yys[YYMAXDEPTH]; ... > yyps= &yys[-1]; >It seems to me that negative indices on arrays are probably not portable. Yacc doesn't actually dereference this pointer; it only uses it to initialize the stack pointer for its inc-push, pop-decr stack. yyps will get used in a phrase like *++yyps = uhlrich to push uhlrich onto the stack, and zwingli = *yyps-- to pop zwingli off. Portable? ANSI says that that pointer is undefined, but I can't imagine it ever causing any problems. Unless there is an architecture where one can decriment a pointer, increment it, and not get the original value back (I'd be surprised, but not terribly surprised), it's plenty portable, since yacc never dereferences it. They could use a push-inc decr-pop stack, for which the equivalent initialization would be yyps = yys; which looks cleaner and portabler. But the advantage to using their approach is that yyps points AT the top item, not at the top free space; this makes it easier to look at the top of the stack without popping, which yacc does quite often. Since the advent of LALR, parsing is cheap enough that it doesn't take up much of the compiler's time anyway; I'd bet this doesn't make much of a difference...