home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!ucbvax!amex-trs.com!gonzalod
- From: gonzalod@amex-trs.com (Gonzalo Diethelm)
- Newsgroups: comp.lang.c++
- Subject: yacc and C identifiers
- Message-ID: <9209050134.AA43930@cs90code.csv-tgsc.amex-trs.com>
- Date: 5 Sep 92 01:34:52 GMT
- Sender: daemon@ucbvax.BERKELEY.EDU
- Lines: 60
-
-
-
- Distribution: world
-
- Hello everyone,
-
- Two questions about yacc. Assume I'm trying to implement a C compiler:
-
- 1. How do you handle identifiers? By this I mean, let's say the
- lexer stores identifiers in the symbol table and returns an ID token
- to the parser, how do I access the identifier from the parser?
- What I'm doing now is having a production
-
- id : ID
- {
- $$ = yylval;
- }
-
- where the lexer sets yylval to the position in the symbol table
- the identifier is stored in. This works, but I'm not sure it is
- the correct approach. I know I could define the type of the parser
- stack to be a union and store there the value of the identifier
- (position in symbol table?). Which approach is better? Is there
- another solution superior to any of these?
-
- 2. How would you handle name spaces? For example, how could you differentiate
- between the var in
-
- int var;
-
- and the var in
-
- struct s { int var; };
-
- or, even better, between all these vars
-
- struct s1
- {
- int var;
- struct s2
- {
- int var;
- union u1
- {
- int var;
- float f;
- }
- }
- }
-
- I CAN think of ways to do this, but somehow I feel the parser itself
- has enough information stored in its states to handle the name spaces.
-
- Any pointers are welcome. Examples are preferred... 8^). Thanks in advance.
-
-
- gonzalod@amexphx.amex-trs.com
- Gonzalo A. Diethelm (602)375-8410 home
- 16220 N 7th St Ap 1314 (602)492-3536 office
- Phoenix, AZ 85022 (602)492-4248 FAX
-