Right now, my idea is to use callback functions. e.g. if I had this YACC rule:
r : a b c { return ruleImplForR(%1, %2, %3); }
then ruleImplForR would be defined in Nim like:
type Type = ref TypeBase proc ruleImplForR(a, b, c: Type): Type {.cdecl, exportc: "ruleImplForR".} = GC_unref a GC_unref b GC_unref c echo a.a result = makeTypeFrom a, b, c GC_ref result
Is this safe? Will this cause memory leaks or segfaults?
Is this safe?
No.
Will this cause memory leaks or segfaults?
Yes.
@Araq So is there any way to do this? Or am I running into a brick wall?
I was guessing maybe the Boehm GC might work better here, since it's conservative?
@Varriount Uhh...use Nim from YACC...
Basically, I want to have YACC productions that return Nim objects, then I want to be able to access and manipulate those objects from by Nim code.
FYI, I know about the pegs module. I love PEGs, but I can't use them for anything more complex than simple configuration file parsers and such. My brain just likes LR thinking better. :)
@kirbyfan64sos, have you considered using dparser?
http://dparser.sourceforge.net
It's a great GLR parser in C with lots of features. It allows to generate parser tables on the fly given grammar. No need to generate sources! And it should be pretty easy to do Nim bindings for it. I've done a port of it to D once.