3 ms·
> For example when I’m traversing the AST when I’m looking at the node { type: "num", value: 10 }, without doing extra work to go back up the tree I have no way
by _a_a_a_ 3y ago
> For example when I’m traversing the AST when I’m looking at the node { type: "num", value: 10 }, without doing extra work to go back up the tree I have no way to tell that it belongs to the name “ten”.
There's a very easy way to do it, simply add a pointer from the child back up to the parent. It means you can't share AST nodes but it's damn fast and, once debugged, very easy to maintain.
I've done this on my personal project and so a question to everyone: when I originally heard of using datalog in compilers it seemed like a very good idea, like it was promising some real value somewhere, but I've seen examples that show you can do trivial type checking – but I do that myself and it's very, very easy. Perhaps I'm looking at this wrong? If I'd used data log then I could knock at a few hundred lines of code scattered around the AST objects, but surely I can do more than that with datalog? I feel I'm missing something, and the crowd here seems knowledgeable so any good pointers (good = simple, because I'm a n00b) would be incredibly helpful!
(I am aware of some really advanced stuff like BDDBDDB (https://suif.stanford.edu/bddbddb/ https://suif.stanford.edu/bddbddb/), so advanced I can't even follow it, I'm looking for something between the triviality of type checking and the complexity of full dataflow – the problem here may be a personal one, in that I might need to have to write a dataflow implementation to get a really good 'feel' for it, and then I might 'get' the value of using e.g. datalog, I don't know, but any guidance welcome) this will feed into an actual working project).