[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lexer rewind?



Hi all,

I'm working on a custom lexer and parser to solve the typedef problems with
the C grammar I posted a few weeks ago... AND... I have a tricky bug.

Problem: typedef_name and identifier have identical lexical syntax
Solution: parser adds typedef_names to a hashtable when they are declared.
The lexer checks this hashtable before deciding if the token is an
identifier or a typedef_name.

This works fine... EXCEPT when the typedef_name is used immediately after
declaration:

   typedef int x;
   x g;

The reason for this is that the parser is LALR(1) and not LALR(0). It relies
on the second x to be lexed before it can recognize the first statement as a
typedef declaration. Of course this means that the second x is lexed as an
identifier, not a typedef_name.

What I really need to be able to do is tell the lexer to rewind, or
re-evaluate it's current token when a typedef declaration has been parsed...
I have tried calling lexer.filter() from the parser (with some hacking) but
this does not have the desired effect.

Can anyone help?

Thanks in advance,

Roger



------------------------------------------------------------------------
ninthave.net                                          p: +61 7 3870 8494
Web Hosting                                           m: +61 405 048 371
Web Design                                    w: http://www.ninthave.net
Programming                                      e: r.keays@ninthave.net
------------------------------------------------------------------------
http://groups.ninthave.net     Complete hosting solution for communities
http://billshare.ninthave.net         The easy way to manage your bills!
http://pic.ninthave.net                    THE C compiler for PIC micros
------------------------------------------------------------------------
http://clubs.sport.uq.edu.au/uqtrifit                  UQ Triathlon Club
http://groups.msn.com/SunshineCoastCycling   Sunshine Coast Cycling Club
http://groups.ninthave.net/uqdance                         UQ Dance Club
http://www.cashflowclub.org.au                          UQ Cashflow Club
http://groups.msn.com/uQRomanceLanguagesClub   UQ Romance Languages Club
------------------------------------------------------------------------