One problem with automatic space management for attributes in a top-down parser occurs in lists and sequences.

Question:

One problem with automatic space management for attributes in a top-down parser occurs in lists and sequences. Consider for example the following grammar:

block → begin stmt list end
stmt list → stmt stmt list tail
stmt list tail → ; stmt list | ∈
stmt → . . .

After predicting the final statement of an n-statement block, the attribute stack will contain the following (line breaks and indentation are for clarity only):

block begin stmt list end
stmt stmt_list_tail ; stmt_list
stmt stmt_list_tail ; stmt_list
stmt stmt_list_tail ; stmt_list
{ n times }

If the attribute stack is of finite size, it is guaranteed to overflow for some long but valid block of straight-line code. The problem is especially unfortunate since, with the exception of the accumulated output code, none of the repeated symbols in the attribute stack contains any useful attributes once its substructure has been parsed.

Suggest a technique to “squeeze out” useless symbols in the attribute stack, dynamically. Ideally, your technique should be amenable to automatic implementation, so it does not constitute a burden on the compiler writer.

Also, suppose you are using a compiler with a top-down parser that employs an automatically managed attribute stack, but does not squeeze out useless symbols. What could you do if your program caused the compiler to run out of stack space? How could you modify your program to “get around” the problem?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: