I want to implement a new language, and I would like to do it in C, with the famous flex+yacc combination. Well, the thing is, writing the whole AST code is very time consuming. Is there a tool that automatically generate the constructors for the structs?
I would like something with the following behavior:
input:
enum AgentKind {A_KIND1, A_KIND2};
typedef struct Agent_st
{
enum AgentKind kind;
union {
struct {int a, b, c} k1;
struct {int a, GList* rest} k2;
} u;
} Agent;
output:
Agent* agent_A_KIND1_new(int a, b, c)
{
Agent* a = (Agent*)malloc(sizeof(Agent));
a->kind = A_KIND1;
a->k1.a = a;
...
...
return a;
}
Agent* agent_A_KIND2_new(int a, GList* rest)
{ ... }
Thank you!