Re: Writing a C/C++ compiler in C++

vbdis@aol.com (VBDis)
4 Feb 2004 21:51:31 -0500

          From comp.compilers

Related articles
Writing a C/C++ compiler in C++ dezakin@usa.net (2004-01-22)
Re: Writing a C/C++ compiler in C++ david.boyle@ed.tadpole.com (2004-01-31)
Re: Writing a C/C++ compiler in C++ haberg@matematik.su.se (2004-02-01)
Re: Writing a C/C++ compiler in C++ jo@spiffy.ox.compsoc.net (Joel Dillon) (2004-02-01)
Re: Writing a C/C++ compiler in C++ vbdis@aol.com (2004-02-01)
Re: Writing a C/C++ compiler in C++ dezakin@usa.net (2004-02-01)
Re: Writing a C/C++ compiler in C++ vbdis@aol.com (2004-02-04)
Re: Writing a C/C++ compiler in C++ hkaiser@users.sourceforge.net (2004-02-12)
Re: Writing a C/C++ compiler in C++ jakacki@hotmail.com (2004-02-12)
Re: Writing a C/C++ compiler in C++ jo@spiffy.ox.compsoc.net (Joel Dillon) (2004-02-13)
Re: Writing a C/C++ compiler in C++ vbdis@aol.com (2004-02-26)
Re: Writing a C/C++ compiler in C++ walter@digitalmars.com (Walter) (2004-02-26)
| List of all articles for this month |
From: vbdis@aol.com (VBDis)
Newsgroups: comp.compilers
Date: 4 Feb 2004 21:51:31 -0500
Organization: AOL Bertelsmann Online GmbH & Co. KG http://www.germany.aol.com
References: 04-02-019
Keywords: C++, practice
Posted-Date: 04 Feb 2004 21:51:31 EST

vbdis@aol.com (VBDis) schreibt:


>[The lexer is affected by the grammar to the extent that it has to
>know what tokens are type names and which ones are variable names.
>-John]


A C/C++ lexer must not know anything about type names. Only in the
very last stage, after all preprocessing has been done, the
preprocessor tokens are converted into language/parser tokens.


In my current implementation I tried to use a single symbol table, for
both the preprocessor and the parser. But this seems to be impossible,
since the preprocessor can have only one set of macro names, whereas
the application code can use the same (local) name for various
purposes. Sometimes also the same names are defined differently for
the preprocessor and the parser, e.g.:
    #define some_type some_type


Finally the same names can reside in multiple namespaces. A lexer
cannot know easily which namespace applies to a symbol, at least I'd
leave that decision to the parser and its tables, and leave the lexer
and preprocessor in its own namespace.


DoDi


Post a followup to this message

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