I'm trying to build a tree to make a parser. My english isn't so good so I will give an example:
function int hello(int a,b,c,d ; char f)
trying to build this tree:
ARGS
/ \
int char
/ | \ \
a b c f
The code I already tried (tried to run just a part to see if it works cus my args grammar im stuck too):
type
: types ids ($$=addSons($1,$2);) {} //$2 will be son of $1
;
types
: INT {$$=newNode(yytext); }
| CHAR {$$=newNode(yytext); }
;
ids
: id {$$=$1}
| idss {$$=$1}
;
idss
: id ',' idss {$$=$1;}
| id ';' {$$=$1;}
;
id
: ID {$$=newNode(yytext); }
;
but it doesn't work. My function addson()
accepts a different number of variables and every time the first arg is father of the rest sons.
If I send son after son the function will add the last son to the next index of the sons automatically.
So my question is if there is any grammar(or an other solution) that can help me so I can connect this tree, unfortunately the grammar of args im stuck too with the same problem.