4 ms·
Racket isn't really a source to source compiler/interpreter (you could try to write a compiler that converted racket into your language of choice, but that can
by hyperion2010 9y ago
Racket isn't really a source to source compiler/interpreter (you could try to write a compiler that converted racket into your language of choice, but that can often be quite difficult). Everything ultimately has to pass through Racket's language semantics, so matching implementation details requires a lot of work if the underlying language spec is large. The #lang C example down below sidesteps these issues because it acts as a pass through to the system c compiler and then handles returning those results into racket, essentially it delegates the language semantics to the c compiler and only deals with how to map the results of calling c code back onto racket objects. Similar issue with the FFI if you want to translate from one language to another, you still have to go through the process of mapping language semantics.
Two examples where languages/parsers have been implemented in racket:
Algol60 is the best and most complete example https://docs.racket-lang.org/algol60/index.html https://docs.racket-lang.org/algol60/index.html.
A python parser has been implemented https://github.com/dyoo/ragg/blob/master/ragg/examples/python-grammar.rkt https://github.com/dyoo/ragg/blob/master/ragg/examples/pytho...
- araes 9y agoThank you for the clarification. Even after two articles I obviously still didn't fully get it. Appreciate the help, and the example links.
- fiddlerwoaroof 9y agoRacket uses macros to transform your language’s syntax into valid racket code, which is then interpreted.
- skrishnamurthi 9y agoNo, this is far too glib, and the last part is wrong. See https://www.hashcollision.org/brainfudge/ https://www.hashcollision.org/brainfudge/ instead.
- skrishnamurthi 9y agoTry reading https://www.hashcollision.org/brainfudge/ https://www.hashcollision.org/brainfudge/ and see if that helps.