|
|
|
|
|
by villedepommes
3181 days ago
|
|
> Go actually has Yacc as a built in tool (although know Lex). Interesting. Did they combine both a lexer and a parser into one tool? lex,flex, and re2c are typically standalone tools (lexers) that tokenize input, whereas yacc and bison are parsers that parse those tokens into ASTs (usually). |
|
No. They give you an interface definition for the lexer and you can implement the methods however you see fit as long as it matches the interface.
Which I found annoying as there are some tedious parts to writing a lexer as soon as you have a language requiring multi-rune tokens with common prefixes.[1]
Apparently the back story is that go needed a parser generator but they didn't need a lexer so they only built just the one out of necessity.
I read some places that they would welcome pull requests for a lex/flex equivalent.
[1] A `rune` in GoLang is like a `char` in C only it stores multi-byte characters where as in C it is more analogous to a single `byte`