4 ms·
I would like to mention that most, if not all, of the Go compiler and related utilities is written in Go itself, with high quality, open source code that can be
by etatoby 10y ago
I would like to mention that most, if not all, of the Go compiler and related utilities is written in Go itself, with high quality, open source code that can be found in the "go" package of the standard library:
https://golang.org/pkg/go/ https://golang.org/pkg/go/
I would recommend using that as a template for one's own compiler, because it's written in idiomatic Go (originally by the language creators) and is cleanly split across abstraction boundaries (packages "scanner", "parser", "ast", and so on.)
There's also a smaller, simpler parser in the "text/template/parse" package, that is used to parse the templating languages in "text/template" and "html/template". As an introduction to it, I recommend the talk "Lexical Scanning in Go" by Rob Pike:
https://www.youtube.com/watch?v=HxaD_trXwRE https://www.youtube.com/watch?v=HxaD_trXwRE
- jerf 10y agoActually, after a quick examination of the Go libraries, I'm not sure I can agree that it's "idiomatic Go". I still see many things that strike me as "artifacts of the C conversion" more than "the way someone would have written this from scratch". The careful package split is something to be copied, though.
- iso-8859-1 10y agoThe conversion from C to Go was done in 2014, so it is surprising that it is not complete yet. See "Go, From C to Go by Russ Cox" (with video) at https://github.com/gophercon/2014-talks https://github.com/gophercon/2014-talks
- f2f 10y agoit is complete, but it's a conversion, not a rewrite. i doubt anyone will spend the time to rewrite the compiler in idiomatic Go soon. bigger fish to fry :)
- stcredzero 10y agoWhere is a good place to read "idiomatic Go?"
- coldtea 10y ago>I would like to mention that most, if not all, of the Go compiler and related utilities is written in Go itself, with high quality, open source code High quality? Isn't the compiler since 1.5 auto-generated from C for the most part, and quite crap with regards to optimizations/readability?