Most effective method of representing an AST in Go

I’m trying to implement a simple compiler for a toy language in Go and I was wondering if anyone has any advice on the most effective / simple way of representing an Abstract Syntax Tree in Go.

I’m not an Go expert but maybe you can look at the parser of otto: https://godoc.org/github.com/robertkrimen/otto

Look here for the AST package code on GitHub:

Maybe this helps.

It might be worth looking through https://golang.org/pkg/go/ast/ to see how go represents its own Abstract Syntax Tree. Your target language might be different, but a lot of the functionality should be similar

The Go AST is pretty complicated and could use a redesign. Well, everything could use a redesign, but the Go AST has actually been talked about as needing one.

For a simpler example, you might have a look at text/template/parse in the standard library. node.go has the AST definition; parse.go builds it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.