What is the difference between lex/yacc and fslex/fsyacc?
Asked Answered
L

2

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?

Lyte answered 14/2, 2010 at 5:7 Comment(0)
V
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.

Veracruz answered 14/2, 2010 at 5:38 Comment(1)
Note that as does not work in fslex, which is an infuriating limitation.Bind
L
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...

Lupien answered 14/2, 2010 at 5:21 Comment(1)
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! :-)Lyte

© 2022 - 2024 — McMap. All rights reserved.