For those using Go, have no fear! There’s an implementation of yacc, goyacc, that is as horribly undocumented as traditional C versions. That being said, the documentation you find for C should match fairly closely for goyacc, and I’ve used it successfully a few times, including just last night.
Does that work well with goyacc? I guess since goyacc just requires conforming to an interface it shouldn’t be a big deal. I just tend to write state machines and copypasta it and adapt to new use cases. Would really like to see a more traditional lex like generator though. Maybe one day I’ll get inspired…
A long time ago I wrote golex, a lexer generator designed to almost be identical in input format to flex. I’ve reuploaded it below; despite the last substantive change being made in 2012, it still compiles and runs fine!
Good questions! I don’t know if I’ve tested it with goyacc, but integrating it shouldn’t be any harder than integrating flex/bison. It’s unlikely to be reentrant as is, though it’s a pretty simple change.
For those using Go, have no fear! There’s an implementation of yacc, goyacc, that is as horribly undocumented as traditional C versions. That being said, the documentation you find for C should match fairly closely for goyacc, and I’ve used it successfully a few times, including just last night.
I don’t know of a lex equivalent, though.
nice approach to lexing in go: Lexical Scanning in Go
Does that work well with goyacc? I guess since goyacc just requires conforming to an interface it shouldn’t be a big deal. I just tend to write state machines and copypasta it and adapt to new use cases. Would really like to see a more traditional lex like generator though. Maybe one day I’ll get inspired…
it has been a while since i’ve used it, but this function is more or less what goyacc uses, if i remember right: https://talks.golang.org/2011/lex.slide#42
there are ragel to go tools out there, and http://crypto.stanford.edu/~blynn/nex/ is more like lex.
A long time ago I wrote
golex, a lexer generator designed to almost be identical in input format toflex. I’ve reuploaded it below; despite the last substantive change being made in 2012, it still compiles and runs fine!https://github.com/kivikakk/golex
nice, i’ll check it out the next time i need lexing :)
Very nice! It doesn’t look like it has out of the box compatibility with goyacc, nor is it reentrant, is that accurate?
Good questions! I don’t know if I’ve tested it with goyacc, but integrating it shouldn’t be any harder than integrating flex/bison. It’s unlikely to be reentrant as is, though it’s a pretty simple change.
I appreciate this a lot. I tend to know enough to be dangerous with lex and yacc, rather than a deep understanding.