delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/06/17:30:25

From: sparhawk AT eunet DOT at (Gerhard Gruber)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Writing a simple compiler
Date: Mon, 06 Jul 1998 20:36:26 GMT
Organization: Customer of EUnet Austria
Lines: 46
Message-ID: <35a720ea.2211979@news.Austria.EU.net>
References: <359eebbc DOT 5439034 AT news DOT uow DOT edu DOT au>
NNTP-Posting-Host: e188.dynamic.vienna.at.eu.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Destination: blp01 AT uow DOT edu DOT au (Brett Porter)
From: Gruber Gerhard
Group: comp.os.msdos.djgpp
Date: Sun, 05 Jul 1998 03:03:04 GMT:

>Hi, this ones for the compiler gurus. 
>
>I'm writing a simple compiler based on a C-like language. Everythings
>doing alright as far as using Flex and Bison to parse the input. But
>now I've got to generating code and stumbled, mainly in the area of
>reducing expressions - as far as wanting to reduce 2*2 to 4 but
>generate code for 2*var. Anyone that could simply explain how to do
>this in Bison/Yacc I'd appreciate it, or a decent website/book on
>compilers that is relatively simple and straightforward. I've tried
>the GCC source, but I can't seem to get the big picture when it comes
>to looking over c-parse.y

I can recommend "lex & yacc" from O'Reilly. That book is really great an it
has a SQL parser and a C commentline parser as examples where they explain
everything about lex and yacc. ISBN is 1-56592-000-7 and should cost USD
$29.95.

Is you parser able to handle the continuation of sourclines via the "\"
character? I tried to figure that one out but I have problems defining a
syntax for lex.

In C it is legal to write a line like this:
#i\
n\
c\
lude\
<stdio\
.h>

Dou you have any idea (or anybody else) how to solve this?
I checked out the sources for gcc but they wrote their own lexer so I can't
see anything there.

--
Bye,
   Gerhard

email: sparhawk AT eunet DOT at
       g DOT gruber AT sis DOT co DOT at

Spelling corrections are appreciated.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019