inherited attributes

Oct 27, 2010 at 1:53 PM
Edited Oct 29, 2010 at 12:37 PM


I'd like to know if gppg supports inherited attributes. I tried using $0, $-1 etc. in semantic actions, but

that didn't work because gppg only allows positive values for $n.

Oct 30, 2010 at 2:29 AM

Hi cybernaut.

You are correct, GPPG range checks symbolic expressions within semantic actions to ensure that they resolve to a valid symbol in the production right-hand-side.

I realize that some parser generators allow zero or negative symbols to access semantic values (or location markers) further down the push-down stack.  Sometimes this can be useful, but is a little tricky. There is the classic result, due to Knuth if my memory hasn't tricked me, that the "viable prefixes" for any given reduction are given by a regular expression.  This is why it is possible to use a finite state automaton to recognize these prefixes.  However this means that you only have certainty as to what is on the stack below the current right-hand-side in the special case that the language of viable prefixes for that particular production all end with the same symbol or symbols. 

Nevertheless, if it is useful on occasion I am reluctant to ban the practice outright.  I could either (1) make a failed bounds check into a warning rather than an error, or (2) invent a command-line option that says "let me use zero and negative symbols".

I have an update ready to upload soon (the source is already in the repository) so I could incorporate this change as well if I get encouragement.

Ummm, and sorry to those readers who understand all of this technical detail already.  I don't want to teach my Grandma to suck eggs, but I do want the explanation to be clear to all the readers.



Nov 8, 2010 at 8:01 AM

Thank you for your reply, John. Sorry for being a bit late to respond.