Hello! Does someone know of tutorials that focus on building #lang languages with interpreters as “backends” rather then source-to-source compilers (expanders)?
I’m guessing it should be down at the expander level, but not sure how to go about it. Also I was wondering, with read-eval-print design, were exactly does the printer fit, in the expander..?
I like racket’s idea of syntax objects and all the libraries, but a full blown source-to-source compiler is likely overkill for what I am working right now…
it might not, have you read Beautiful Racket?
yup, read it quite a whole ago (year?)! It’s quite nice, but I think it does follow this source-to-source approach mostly? I’ve been playing around with interpreters tutorials written in other languages (Python, ML, Go, etc) but I just feel racket would be more convenient..!
also you could make a module evaluator based on your language, to make your own eval https://github.com/racket/racket/wiki/Sandbox-examples
what do you want to do?
An interpreter in which a lot of syntax can be redefined on the fly (a bit like what’s has been explored in Honu and Rhombus)
a controlled natural language
I mean I’ve followed quite a lot of typical lisp meta-circular evaluators
even seen a few examples in racket but they don’t take advtange of #lang from what I could see
The sand-box examples look promising
will look more carefully thanks @cris2000.espinoza677
> a full blown source-to-source compiler is likely overkill I’m not sure why you think writing interpreter is easier than the “source-to-source” approach. The point of the compilation approach is that you don’t need to bother giving semantics to primitive constructs, because Racket has already done that for you. You can just reuse whatever Racket gives to you already.
you’re welcome, although you started to scare me, because i have some idea of what you want, but you seem further in front in your racket journey than me lol
yeah what @sorawee said
problem is I’m writing a portuguese interpreter
so… lots of mappings
sure so? isn’t like you dont have a lot of mappings with an interpreter
some approaches to keeping variables names in interpreted languages need a hash map
yeah that’s what I’ve done in Python basically
used a hash to keep the environment
what would be your approach to make it easier to have a portuguese interpreter? :thinking_face:
I don’t see how sandbox will solve your problem, btw.
In any case, if you really want to interpret, you can just redefine #%module-begin
to quote the whole program and call your interp
function on the quoted value.
you know racket identifiers are utf–8?
@sorawee yeah thought of that was wondering if that would be the way
yup
it’s just easier to stay at Subject Verb Object all the time
then having to translate to VSO and back
Can you give me an example AST that you are working on?
actually I don’t aim to have AST…
I’m really curious if the macro approach would be difficult/tedious as you said
TDOP
I mean, sure, but you gotta operate on some representation of the program. I meant those representation.
Maybe it’s not as bad as I think, it’s just I’m quite confortable with interpreters versus compilers..!
plus don’t have to much time to go into the compiler route
I mean I sort of have an AST, but I just build it along the way and interpret it
blocks inside blocks
Inspired a lot by CGOL/TDOP
also construction grammar from cognitive linguistics, where there is not distinction between lexicon and grammar really
it’s just a single dynamic thing
anyways thanks for the links and tips @cris2000.espinoza677 @sorawee, you’re likely right in many aspects, I just don’t have the time to explore them for now :sweat_smile:
One issue with dynamic syntax is how do you compile non-delimited function (logo style) for which you only know how many arguments you take at runtime? I mean the only solution I can think is a fully typed language, possibly with good inference, but that’s even more overkill hehe…
Just saw they have similar discussions with Honu and Rhombus
ok so this is going over my head. but you want a function that accepts many arguments?
assuming you have higher-order functions note
possibly, but ideal not more then 4 or 5, and most would be 1 (intransitive verb) 2 (transitive verb) or 3 (ditransitive verb)
but [] for example is a n* argument expression
same goes for {} "" ()
and that would be the simplest use case
https://docs.racket-lang.org/reference/procedures.html?q=keyword-apply#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._make-keyword-procedure%29%29\|make-keyword-procedure you have that, and change #%app? … i actually dont know what to say… ill see myself out, idk if i can help you… I hope you find someone you can, actually you should ask in #general
yeah I mean I’ve thought about keywrods (I like Python and Smalltalk in that sense)
but sometimes keywords get in the way
you could have a syntax transformation between what you want to keywords idk.
@cris2000.espinoza677 yeah maybe I should try #general but wanted to check for any obvious tutorials first I might have missed
Yeah cool idea
transforming to keywords
thanks for your time @cris2000.espinoza677]
you’re welcome!
-> Arrow notation could be a potential alternative syntax for lambda.