An interpretor that works more like a transformer? #1233
-
I'm trying to write an interpretor for the openscad programing language, with the back-end replaced by folgeman/sdf. Starting from the basic calculator example worked wonderfully, I had basic functions implemented very quickly and was able to get to rendering simple objects in only a few hours of work. Where it fell apart though is when I needed to implement scope. Scope itself isn't too hard, as all I need to do is add a child to a chainmap when entering a scope and restore the old dict when exiting the scope. What is a challenge is that the transformer is leaf-first. So I tried to use an interpreter instead. I'm sure I can get this to work, just it does make things a lot more complicated for me. What I'd like is to be able to have some combination of My attempts at doing it as just a normal interpreter do work, just the code is IMHO a lot less readable. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
As you probably noticed, My idea would be to add a way to make sure that the v_args wrapper class can be made aware that it's part of a Interpreter and not a normal Transformer and make any required changes, and therefore to partially more |
Beta Was this translation helpful? Give feedback.
-
Yeah, that's sort of where I ended up from looking at the code. It was a bit complicated though, so I figured I'd ask a second opinion. |
Beta Was this translation helpful? Give feedback.
-
As an aside, v_args seems to work fine with the Interpreter, just you can currently only use it with terminals. |
Beta Was this translation helpful? Give feedback.
As you probably noticed,
v_args
is basically completely incompatible withInterpreter
. While it might be possible, it's not an "easy hack". I don't really have an alternative suggestions right now, this is something that someone would have to spend some time on to implement.My idea would be to add a way to make sure that the v_args wrapper class can be made aware that it's part of a Interpreter and not a normal Transformer and make any required changes, and therefore to partially more
visit_children_decor
into a similar system as the current VArgsWrappers. But I didn't plan out anything specifically