8

I'm learning F# because I'd like to write a lexer and parser. I have a tiny bit of experience with this sort of processing but really need to learn it properly as well as F#.

When learning the lexing/parsing functionality of F#, is studying lex and yacc sufficient?

Or are there some differences that means code for lex/yacc will not work with fslex and fsyacc?

Alex Angas
  • 59,219
  • 41
  • 137
  • 210

2 Answers2

9

I personally found these OcamlLex and OcamlYacc tutorials excellent resources to get started -- easy to follow, and you can translate most everything in those tutorials for FsLex/FsYacc almost verbatim.

Juliet
  • 80,494
  • 45
  • 196
  • 228
5

Well, with lex and yacc, you put C/C++ code in the 'actions', whereas with fslex and fsyacc you put F# code there, but I presume you know this?

I think they are otherwise based on the same (established/ancient) tokenizing and parsing technologies, so the general structure/behavior of the grammar should be similar, if that's what you're after...

Brian
  • 117,631
  • 17
  • 236
  • 300
  • I'm still learning both F# and lex/yacc. The nature of functional programming seems to make it harder to debug so I don't want to run into weird behaviour because I'm using the wrong syntax! :-) – Alex Angas Feb 14 '10 at 07:17