I've "finished" my Go AWK interpreter and released v1.0.0 now. I've fixed several bugs, and also sped up the interpreter significantly, primarily by:
1) Resolving variable names to integers at parse time so we can do []value lookups instead of map[string]value lookups at runtime 2) Using normal error returns instead of panic/recover internally for interpreter errors (but oh for the proposed "check" keyword to make this less verbose!) 3) Using switch/case to switch on binary operation type instead of looking up the operation in a map of functions 4) Avoiding allocations in many instances Here's a write-up about GoAWK for those that are interested: https://benhoyt.com/writings/goawk/ It's pretty much a toy project, not being used for anything real, but it seems to be in a good shape. Feedback welcome! -Ben On Fri, Aug 24, 2018 at 5:13 PM Ben Hoyt <benh...@gmail.com> wrote: > I recently wrote an AWK interpreter in Go: > https://github.com/benhoyt/goawk > > It's a pretty simple implementation: hand-rolled lexer, recursive-descent > parser, and tree-walk interpreter. It's pretty complete according to the > POSIX spec, and it passes the AWK ("one true awk") test suite as well as my > own unit tests. > > In some quick tests I ran, I/O speed is on a par or better than AWK but > the interpreter itself is quite slow -- about 5x slower for a lot of > things. I hope to add some proper benchmarks soon. I have a pretty good of > why and how to fix it: variable lookup and assignment is slow, and I'm > planning to fix by resolving more things at parse time. > > One thing that's a bit funky about AWK is its type handling: string values > can be real strings or "numeric strings" (numbers that came from user > input). I'm currently passing the "value" struct (see interp/value.go) > around by value. I still need to test if that's a good idea > performance-wise or not. > > I'd love to hear any comments, bug reports, or -- especially -- code > reviews. > > -Ben > > -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/kYZp3Q1KKfE/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.