My simple JSON compiler works fine, the problem is that in my interpreter I’m allowing to extend the parser, example is this simple code:
(set-special! "<>" 'x)
(define (x arg)
The evaluation work together with the parser each S-Expression is parsed then evaluated then next expression is parsed.
when evaluating it, it prints
The problem is that this happen while evaluating the code,
set-special! change the parser and add new token
<> that add hook to the parser that return vector.
When I’m compiling the code to JSON, I’m just parsing the code and not evaluating it, so function x is not known and new syntax is also not known, I would need to execute the code to know them since they are runtime.
And when I’m evaluating compiled JSON I’ve got exactly same code not
(print #(10)), so it’s just normal symbol in the middle of the print. Also because this syntax is invoked by the parser, that is not invoked when evaluating the code, so I got error that symbol
<> is not defined, in Scheme
<> is normal identifier that can be variable, function or macro.
My question is how would you handle this case? What advice can you give me?
One note is that I don’t have proper expansion time for macros yet and all macros are executed at runtime, they are like functions that return code that is evaluated. When the code was only interpreted this didn’t matter much.
Will making this work require to write proper expansion time. I’m not sure how Common Lisp do this, since it have similar concept of compiler and reader macros that work like my syntax extensions.