Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #103

Maintaining scope while parsing C with a YACC grammar

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!198.186.194.250.MISMATCH!news-out.readnews.com!news-xxxfer.readnews.com!news.misty.com!news.iecc.com!nerds-end
From eliben <eliben@gmail.com>
Newsgroups comp.compilers
Subject Maintaining scope while parsing C with a YACC grammar
Date Mon, 25 Apr 2011 05:14:42 -0700 (PDT)
Organization Compilers Central
Lines 31
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <11-04-036@comp.compilers> (permalink)
NNTP-Posting-Host news.iecc.com
X-Trace gal.iecc.com 1303795799 26368 64.57.183.58 (26 Apr 2011 05:29:59 GMT)
X-Complaints-To abuse@iecc.com
NNTP-Posting-Date Tue, 26 Apr 2011 05:29:59 +0000 (UTC)
Keywords parse, symbols, question
Posted-Date 26 Apr 2011 01:29:59 EDT
X-submission-address compilers@iecc.com
X-moderator-address compilers-request@iecc.com
X-FAQ-and-archives http://compilers.iecc.com
Xref x330-a1.tempe.blueboxinc.net comp.compilers:103

Show key headers only | View raw


Hello,

Suppose I'm parsing C with a YACC-like grammar. While parsing this
code:

int main()
{
  int a = 1;
  {  /* internal scope */
    int b = 2;
  }
}

I want to know that the declaration "int b = 2" happens inside an
internal scope. My problem is that the way YACC grammars (and bottom-
up parsing in general) are structured, "int b = 2" is analyzed
*before* the whole block { int b = 2;} so I've seen "int b = 2" before
I've seen the complete block. What is the usual solution to this
problem?

Thanks in advance

[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]

Back to comp.compilers | Previous | NextNext in thread | Find similar


Thread

Maintaining scope while parsing C with a YACC grammar eliben <eliben@gmail.com> - 2011-04-25 05:14 -0700
  Re: Maintaining scope while parsing C with a YACC grammar Robert A Duff <bobduff@shell01.TheWorld.com> - 2011-04-26 12:22 -0400
    Re: Maintaining scope while parsing C with a YACC grammar Robert A Duff <bobduff@shell01.TheWorld.com> - 2011-04-26 14:08 -0400
    Re: Maintaining scope while parsing C with a YACC grammar eliben <eliben@gmail.com> - 2011-04-28 23:20 -0700
      Re: Maintaining scope while parsing C with a YACC grammar Robert A Duff <bobduff@shell01.TheWorld.com> - 2011-05-02 20:19 -0400
        Re: Maintaining scope while parsing C with a YACC grammar "Ira Baxter" <idbaxter@semdesigns.com> - 2011-05-13 17:46 -0500
        Maintaining scope while parsing C with a Yacc grammar Chris F Clark <cfc@shell01.TheWorld.com> - 2011-06-12 20:43 -0400
      Re: Maintaining scope while parsing C with a YACC grammar torbenm@diku.dk (Torben Ægidius Mogensen) - 2011-05-03 09:51 +0200
  Re: Maintaining scope while parsing C with a YACC grammar Paul B Mann <paul@paulbmann.com> - 2011-05-06 10:43 -0700

csiph-web