[erlang-questions] Adding new operators?

David Goehrig dave@REDACTED
Sat Apr 13 20:00:39 CEST 2013


Thanks for that deck, I hadn't seen it before. Funnily enough, I've played with erl_scan and erl_parse, but then got sucked into reading the main loop of the beam and started playing around with adding the low level support there, which felt right. 

I got new opcodes working faster than I got any of the scanner/parser bits working, mostly because the simple C was easier to decypher without knowing the compiler infrastructure. 

Dave

-=-=- dave@REDACTED -=-=-

On Apr 13, 2013, at 6:07 AM, Justin Calleja <calleja.justin@REDACTED> wrote:

> ahh yes Anthony's right, my bad.
> 
> Ok, so this is the first thing that comes to mind then, don't know if it'll help:
> 
> http://www.scribd.com/doc/22451864/Hacking-Erlang
> 
> Regards,
> Justin
> 
> 
> On 10 April 2013 18:31, Anthony Ramine <n.oxyde@REDACTED> wrote:
>> That wouldn't work because you need one new token per operator you want to  add to the language, parse transforms work on abstract syntax trees which are returned by the parser, a level higher than tokens.
>> 
>> On the other hand he can also abuse existing expressions by using them in ways which are illegal in Erlang.
>> 
>> For example he could write a parse transform for a parallel send operator like this:
>> 
>>         +[Pids/parallel] ! Message.
>> 
>> This is beyond ugly but at least it's quite obvious that some spooky action at the distance is going on.
>> 
>> Regards,
>> 
>> --
>> Anthony Ramine
>> 
>> Le 10 avr. 2013 à 16:41, Justin Calleja <calleja.justin@REDACTED> a écrit :
>> 
>> > Hi David,
>> >
>> > You should be able to do that with a parse_transform/2. Look up parse transform: you basically get to implement a function which the compiler calls at compilation time passing it a formal representation of the source code it's compiling (a.k.a abstract forms... though I'm not entirely sure about the terminology).
>> >
>> > You can then use the erl_syntax module to manipulate these forms.
>> >
>> > cheers,
>> > Justin
>> >
>> >
>> > On 8 April 2013 08:21, Anthony Ramine <n.oxyde@REDACTED> wrote:
>> > Hello David,
>> >
>> > A fancy way to extend the Erlang syntax would be to have something like Camlp4, a powerful and extensible preprocessor for OCaml. It has a powerful quotation system which it itself uses to implements its parser construct, to extend OCaml's syntax at compile-time. I have began writing a quotation system for Erlang but didn't have the time finish it yet [1].
>> >
>> > Regards,
>> >
>> > [1] https://github.com/nox/otp/tree/brackets
>> >
>> > --
>> > Anthony Ramine
>> >
>> > Le 8 avr. 2013 à 02:12, David Goehrig <dave@REDACTED> a écrit :
>> >
>> > > Next step is integrating into the stack better. But the question remains, what is the best way to add a new operator.
>> > _______________________________________________
>> > erlang-questions mailing list
>> > erlang-questions@REDACTED
>> > http://erlang.org/mailman/listinfo/erlang-questions
>> >
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130413/56971ff1/attachment.htm>


More information about the erlang-questions mailing list