C Language Scoping

Gilberto Persico <gilberto_persico@it.ibm.com>
26 Oct 1997 22:09:50 -0500

          From comp.compilers

Related articles
C Language Scoping gilberto_persico@it.ibm.com (Gilberto Persico) (1997-10-26)
Re: C Language Scoping mss@emsoft.de (Michael S. Schliephake) (1997-10-29)
Re: C Language Scoping hbve@camoes.rnl.ist.utl.pt (Hugo Branco Venancio) (1997-10-29)
| List of all articles for this month |

From: Gilberto Persico <gilberto_persico@it.ibm.com>
Newsgroups: comp.compilers
Date: 26 Oct 1997 22:09:50 -0500
Organization: IBM Italia S.p.A.
Keywords: C, question, comment

Hi All,
I have a question. I'm not a compiler development Guru (but I'm good at
C programming) and I have learned how to use lex & yacc together. I used
the publically available C grammar from Jeff Lee for a special
application, but there is still one thing I can't understand: how can a
symbol be assigned to a scope (global, a function, a structure) during
parsing ??? And if I have the same symbol used in more contexts like the
following example:

struct A
int x;
int y;

void test()
float x;

how can I know in the parser that the first X is an int in scope A and
the second X is a float in scope test ?? I can discover that the first x
is an int, and that is a structure member too, and I also can discover
that is in A scope, but the second time I already have a x symbol in the
scope A, and I still don't know the scope for the second x. I hope my
message is clear .... Should you need the Jeff Lee's C grammar, I can
post it...
[The parser keeps track of the current scope as it's parsing along, and
enters and looks up symbols in the current scope. This is covered in most
compilers texts. -John]

Post a followup to this message

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