sep 19
Bison and Flex
- online docs and descriptions
- See docs directory for local copies of some of this.
## 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
- ANTLR - ANother Tool for Language Recognition (Java)
- "Why program by hand in five days what you can spend five years of your life automating."
# 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 :