For Programmers: Free Programming Magazines  


Home > Archive > Compilers > October 2005 > Using Flex and Bison









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using Flex and Bison
girvinator@gmail.com

2005-10-23, 7:56 am

Hi there everyone.
I am fairly new to programming compilers, although not to programming
in general.

I downloaded Parser Generator (http://www.bumblebeesoftware.com/) which
is simply an IDE for Lex and YACC.

I was just wondering, which way is the best to work on a compiler. Work
on the Lex file first, then the YACC file, and compile? Or the other
way round. I have read many tutorials, and some of the do it the other
way to others.

Also, does anyone know of a good tutorial that I could read, that will
actually COMPILE! All of the ones I have read have needed MAJOR changes
to even attempt to compile!

Anyways, thanks for everything.

-Girvo
Hans Aberg

2005-10-26, 7:01 pm

girvinator@gmail.com wrote:

> I was just wondering, which way is the best to work on a compiler. Work
> on the Lex file first, then the YACC file, and compile? Or the other
> way round. I have read many tutorials, and some of the do it the other
> way to others.


Just compile the file you have edited, be it the .l or the .y
file. Often these two hangs together, so that they often need to be
edited together, so that both needs to be compiled. So might want
writing a "make" script to automate it.

> Also, does anyone know of a good tutorial that I could read, that will
> actually COMPILE! All of the ones I have read have needed MAJOR changes
> to even attempt to compile!


The book by Aho, Sethi & Ullman, "Compilers..." (the "Dragon book")
has a simple Lex/Yacc calculator example, which can easily be made
working with Flex/Bison. Play around with it. Look into the Bison
manual, which shows how to use operator precedents. Then just move
along, either by building or to more advanced examples.

--
Hans Aberg
[The examples from lex&yacc in the comp.compilers archive work. You
may have to remove -ll and -ly from the Makefiles if you have a modern
version of lex and yacc without the separate libraries. -John]

toby

2005-10-26, 7:01 pm

girvinator@gmail.com wrote:
> Hi there everyone.
> ...
>
> Also, does anyone know of a good tutorial that I could read, that will
> actually COMPILE! All of the ones I have read have needed MAJOR changes
> to even attempt to compile!


'info flex' and 'info bison' are valuable introductions - also see:
http://www.gnu.org/software/flex/manual/ &
http://www.gnu.org/software/bison/manual/

I have an example flex/bison project here that should build easily:
http://www.telegraphics.com.au/svn/exprparser/trunk/
Girvo

2005-10-28, 3:57 am

toby wrote:
> girvinator@gmail.com wrote:
>
> 'info flex' and 'info bison' are valuable introductions - also see:
> http://www.gnu.org/software/flex/manual/ &
> http://www.gnu.org/software/bison/manual/
>
> I have an example flex/bison project here that should build easily:
> http://www.telegraphics.com.au/svn/exprparser/trunk/


Also, what is the bset compiler to use? GCC? I am using Dev-C++ and it
comes up with errors for any Lex of YACC file i compile.
[Lex and yacc produce quite portable C. I suspect there are errors in
your action code. -John]
toby

2005-10-29, 9:56 pm

Girvo wrote:
> toby wrote:
>
> Also, what is the bset compiler to use? GCC? I am using Dev-C++ and it
> comes up with errors for any Lex of YACC file i compile.


(According to http://www.bloodshed.net/devcpp.html) Dev-C++ is MinGW
based, which means it is in fact gcc. I have built flex/bison projects
with MinGW, native gcc, CodeWarrior, motorola mrc, and probably others.

--Toby

> [Lex and yacc produce quite portable C. I suspect there are errors in
> your action code. -John]

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com