Re: Generating a simple hand-coded like recursive descent parser

Hans-Peter Diettrich <DrDiettrich1@aol.com>
21 Sep 2006 10:33:15 -0400

          From comp.compilers

Related articles
[14 earlier articles]
Re: Generating a simple hand-coded like recursive descent parser mr.waverlye@verizon.net (Mr.E) (2006-09-11)
Re: Generating a simple hand-coded like recursive descent parser ArarghMail609@Arargh.com (2006-09-11)
Re: Generating a simple hand-coded like recursive descent parser mr.waverlye@verizon.net (Mr.E) (2006-09-11)
Re: Generating a simple hand-coded like recursive descent parser tommy.thorn@gmail.com (Tommy Thorn) (2006-09-12)
Re: Generating a simple hand-coded like recursive descent parser mr.waverlye@verizon.net (Mr.E) (2006-09-16)
Re: Generating a simple hand-coded like recursive descent parser tommy.thorn@gmail.com (Tommy Thorn) (2006-09-18)
Re: Generating a simple hand-coded like recursive descent parser DrDiettrich1@aol.com (Hans-Peter Diettrich) (2006-09-21)
Re: Generating a simple hand-coded like recursive descent parser chris.dollin@hp.com (Chris Dollin) (2006-09-22)
Re: Generating a simple hand-coded like recursive descent parser DrDiettrich1@aol.com (Hans-Peter Diettrich) (2006-09-25)
Re: Generating a simple hand-coded like recursive descent parser chris.dollin@hp.com (Chris Dollin) (2006-09-25)
Re: Generating a simple hand-coded like recursive descent parser DrDiettrich1@aol.com (Hans-Peter Diettrich) (2006-09-26)
Re: Generating a simple hand-coded like recursive descent parser zebedee@zebedee.net (zebedee) (2006-09-28)
Re: Generating a simple hand-coded like recursive descent parser DrDiettrich1@aol.com (Hans-Peter Diettrich) (2006-09-28)
[17 later articles]
| List of all articles for this month |

From: Hans-Peter Diettrich <DrDiettrich1@aol.com>
Newsgroups: comp.compilers
Date: 21 Sep 2006 10:33:15 -0400
Organization: Compilers Central
References: 06-09-02906-09-042 06-09-048 06-09-060 06-09-078 06-09-093
Keywords: parse, C

Tommy Thorn wrote:


> to work, most people think that C is an LALR(1) language or simpler (*).


> (*) It's not. The lexer has to know which names are types, otherwise it
> becomes impossible to tell if the statement
> x * y;
> is a declation of a pointer to x or an expression multiplying x and y.


A more practical example, found in this group already:
      a = (b)-c;
is (b) a type cast, or an expression?


Sorry, I don't remember who "invented" this fine example :-(




As a solution for this problem in my LL(1.5) C parser, I leave the
distinction to a stage between the lexer and parser, inside the
preprocessor. Only in this stage "words" are mapped into keywords,
typenames and other identifiers. The according "symbol" table is
initialized with the C keywords, the preprocessor adds to it all
#defined names, and the parser adds all encountered typedef names. This
procedure works fine, provided that typedefs always have global scope,
as is required in C. C++ makes it more complicated, with namespaces and
local typedefs :-(


DoDi


Post a followup to this message

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