The Design and
Implementation
of Programming
Languages

Fall 2006
course
navigation

sep 19

Bison and Flex
## on cs.marlboro.edu, running ubuntu breezy $ apt-get bison $ apt-get flex $ flex -V flex 2.5.31 $ bison -V bison (GNU Bison) 2.0 $ cd flex_bison_example # create calc.y and calc.l , see "A Bison Primer" $ bison -v -t -d calc.y $ flex -d calc.l $ gcc -g lex.yy.c calc.tab.c -lfl -lm -o calc $ ./calc --(end of buffer or a NUL) 2+3*7 --accepting rule at line 7 ("2") --accepting rule at line 17 ("+") --accepting rule at line 7 ("3") --accepting rule at line 17 ("*") --accepting rule at line 7 ("7") --accepting rule at line 17 (" ") ANS: 23.000000 --(end of buffer or a NUL) ^d --EOF (start condition 0)
Other tools
# see http://www.cs.usfca.edu/~parrt/course/652/lectures/antlr.html $ apt-get install antlr # installs into /usr/share/java $ export CLASSPATH=/usr/share/java/antlr.jar:. $ cd antlr # create expr.g # create Main.java $ java antlr.Tool expr.g $ javac Main.java $ java Main 3+(2*7+5)*2 ^d 41 $ java Main 3++4 line 1:3: unexpected token: +
For a really good time, check out this grad level 20hrs/wk course called "programming languages" at USF (U San Francisco) that uses Java and ANTLR to create XML parsers, postscript interpreters, and lots more :
http://www.cs.usfca.edu/~parrt/course/652/index.html
http://cs.marlboro.edu/ courses/ fall2006/languages/ notes/ sep_19
last modified Monday September 18 2006 8:01 pm EDT