I am looking for a very short working example of flex and bison with an accompanying Makefile which makes use of the builtin rules. I’ve tried several google results that were messy, wouldn’t build, or were in C++ which isn’t acceptable. Good online resources and short sample code is appreciated.
ADDITIONAL
# Makefile example -- scanner and parser.
# Creates "myprogram" from "scan.l", "parse.y", and "myprogram.c"
#
LEX = flex
YACC = bison -y
YFLAGS = -d
objects = scan.o parse.o myprogram.o
myprogram: $(objects)
scan.o: scan.l parse.c
parse.o: parse.y
myprogram.o: myprogram.c
I would like a Makefile which looks approximately like this with attached source files which do something arbitrarily simple.
The flex project itself comes with a decent set of examples, including make files and bison files.
For an excellent intro to the topic, I suggest lex and yacc 2nd edition:
Finally, go here for a quick primer:
Edit:
As Bart mentioned, another source is: http://oreilly.com/catalog/9780596155988/
And the following is the skeleton file I use to start a flex project. It uses gnu getopts for parsing command line options and getting the file name. I make no claims as to portability or ease of use! 🙂
Finally, since people keep checking this out, I also have an example lexer and parser with makefile on github.