Martin Pool wrote: > I was wondering about this the other month, when I wanted to build a > small parser. Are lex and yacc really still the way to go in C?
Lex and yacc (or rather bison, the GNU version) are more than adequate for most parsing tasks, especially if you use the GNU extensions. The only place they really fall down is for parsing really horrid stuff like C++ (ie GNU GCC now uses a hand coded parser for C++ but lex for plain C). The main problem with lex and yacc/bison is that the rest of the code has to be written in C or C++ which IMO are a little too low level for writing compilers (manual memory handling, excessive boilerplate etc). > I probably should have seized the opportunity to learn some ocaml... Ocaml is a language that is especially well suited for parsing tasks and more generally, for writing compilers. These tutorials (adapted from the GNU lex and GNU bison docs) are quite good: http://plus.kaist.ac.kr/~shoh/ocaml/ocamllex-ocamlyacc/ocamllex-tutorial/ http://plus.kaist.ac.kr/~shoh/ocaml/ocamllex-ocamlyacc/ocamlyacc-tutorial/ The things that make Ocaml so nice for parsing/compilers are: - Strong static type safety. - Safe strings. - Garbage collection. - Variant types. - Pattern matching. For reasons why variant types are so nice, see my blog post from last year: http://www.mega-nerd.com/erikd/Blog/CodeHacking/Ocaml/variant_types.html http://www.mega-nerd.com/erikd/Blog/CodeHacking/Ocaml/variant_types_code.html HTH, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "I wouldn't want to create the impression that I wouldn't like the government of the United States to be Islamic sometime in the future." -- Ibrahim Hooper, spokesman for Council of American Islamic Relations. _______________________________________________ coders mailing list coders@slug.org.au http://lists.slug.org.au/listinfo/coders