Re: Maintaining scope while parsing C with a YACC grammar

eliben <eliben@gmail.com>
Thu, 28 Apr 2011 23:20:09 -0700 (PDT)

          From comp.compilers

Related articles
Maintaining scope while parsing C with a YACC grammar eliben@gmail.com (eliben) (2011-04-25)
Re: Maintaining scope while parsing C with a YACC grammar bobduff@shell01.TheWorld.com (Robert A Duff) (2011-04-26)
Re: Maintaining scope while parsing C with a YACC grammar bobduff@shell01.TheWorld.com (Robert A Duff) (2011-04-26)
Re: Maintaining scope while parsing C with a YACC grammar eliben@gmail.com (eliben) (2011-04-28)
Re: Maintaining scope while parsing C with a YACC grammar bobduff@shell01.TheWorld.com (Robert A Duff) (2011-05-02)
Re: Maintaining scope while parsing C with a YACC grammar torbenm@diku.dk (2011-05-03)
Re: Maintaining scope while parsing C with a YACC grammar paul@paulbmann.com (Paul B Mann) (2011-05-06)
Re: Maintaining scope while parsing C with a YACC grammar idbaxter@semdesigns.com (Ira Baxter) (2011-05-13)
Maintaining scope while parsing C with a Yacc grammar cfc@shell01.TheWorld.com (Chris F Clark) (2011-06-12)
| List of all articles for this month |
From: eliben <eliben@gmail.com>
Newsgroups: comp.compilers
Date: Thu, 28 Apr 2011 23:20:09 -0700 (PDT)
Organization: Compilers Central
References: 11-04-036 11-04-038
Keywords: C, parse
Posted-Date: 02 May 2011 00:49:33 EDT

On Apr 26, 7:22 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> eliben <eli...@gmail.com> writes:
> > [There's a couple of possibilities. One is to add separate rules for
> > the open and close braces with action code that increments and
> > decrements the nesting level, so you know when you reduce the
> > declaration what scope it is in. Another is to parse the whole thing
> > into an AST without trying to interpret the symbols other than making
> > pointers to a generic symbol table entry per name, then walk the AST
> > and add the scope and type info. Perhaps people will have other
> > suggestions. -John]
>
> I strongly recommend the "build a tree" solution. It might seem like
> a lot of trouble at first, but it will simplify things in the long
> run.
>
> Do all the interesting work during a subsequent walk of the tree. Or
> multiple walks.


Since it's parsing of C I'm talking about, this approach will have to
somehow handle ambiguity of this kind:


T * x;


This can be either a declaration or a multiplication, depending on
earlier symbol table information (whether T is a type or not).


So are you proposing to build an ambiguous AST that contains *both*
parses and resolve between them in later passes? Or just pick one and
maybe modify it later? Do you have references (papers, books, etc.)
explaining this technique?


Thanks in advance



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.