3 ms·
How to write a parser in Go
- lloeki 8y agotl;dr: write a parser using goyacc, a yacc port that therefore has some impedance mismatch with Go. (go)yacc is LALR(1) I've been using PEG/Packrat implementations providing a more "native" experience to great effect lately, notably ruby's treetop and golang's pointlander/peg. https://github.com/cjheath/treetop https://github.com/cjheath/treetop https://github.com/pointlander/peg https://github.com/pointlander/peg
- rijoja 8y agoThis project gives me I have a solution please give me a problem feeling. I remember looking into yacc a while ago, for some reason but I can't really remember doing why. Might've been for a configuration type of deal, but nowadays I just use json for that because it intersects other areas of the code and therefore saves time.
- jcelerier 8y agoyuck, I'd take boost.spirit every day over this
- naikrovek 8y agogood for you. Maybe try saying something positive next time, even if you have to fabricate it. Or just don't comment.
- gameswithgo 8y agoAnother very good take on this topic that really was the first thing that made it all click for me: https://www.youtube.com/watch?v=HxaD_trXwRE https://www.youtube.com/watch?v=HxaD_trXwRE
- kalekold 8y agoOr you can read this: https://interpreterbook.com/ https://interpreterbook.com/
- stevekemp 8y agoThat's a good read. I extended my version of monkey to add a ton of new features and found it easy: https://github.com/skx/monkey/ https://github.com/skx/monkey/ Over the past two days I also switched a toy-project for deploying software via SSH/SCP to using a lexer/parser, rather than parsing via regular expressions and string-splits. I guess that means that I learned something: https://github.com/skx/deployr https://github.com/skx/deployr
- weberc2 8y agoI played with this last year but couldn’t wrap my head around it. I don’t recall if it was poorly documented at the time or if it couldn’t handle something I was trying to do or if I was just depressed by the generated code quality, but I eventually gave up and tried rolling my own parser by hand. It was the first time I’d done such a thing and I didn’t really understand patterns for writing parsers so I eventually gave up there too. I’m really excited to read Thorsten Ball’s “How to write an Interpreter in Go” book which walks the reader through writing a parser by hand (his blog post about book-writing tools was on the front page here—or maybe it was /r/programming?—yesterday, incidentally).