Here is my top of yacc file.y
%code requires {
struct Id {
char *var;
};
struct Commds;
struct Commd {
struct Id lhs;
};
struct Commds {
struct Commd commd;
struct Commds *next;
};
}
I used this code in my %union
to defined new types for parser.
%union {
char *id;
long long integer;
struct Id Identifier;
struct Commd Command;
struct Commds *Commands;
}
....
%type <Command> command
%type <Commands> commands
I have no problem in using it with $$
-dollars attributes while parse tree is building up while evaluating tokens from my lexer. Unfortunately I would like to use my structures which are defined in the beginning of the file in other methods in %{ codes %}
section. Unfortunately whenever I define function like this:
void add(struct Commd cmd) {...};
I am getting an error: unknown type! I would be grateful for telling me how to make this structs visible to my entire parser.