Mail Archives: djgpp/1998/07/06/17:30:25
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 -