I created a scanner and a parser (with flex and bison respectively) and an AST to implement a Java-Python translator. I don't understand how to manage semantic actions in AST (type checking, variable declaration checking,...), that is where to insert functions that implement these checks and how to connect Symbol table (that I created) to the AST. Considering, for example, this production in the parser:
VariableDeclaration
: VariableName {$$ = varDec_new($1,NULL);}
| VariableName ASSIGNOP ExpressionStatement {$$ = varDec_new($1,$3);}
;
With varDec_new defined as follow in ast.c :
ast_node *varDec_new(ast_node *variableName, ast_node *exprStmt)
{
ast_node *n = newast(AST_VARDEC); // ast_node allocation (in this case for the ast_node AST_VARDEC (type of ast_node)
n->varDec.variableName = variableName; // pointer to variableName struct in AST
n->varDec.exprStmt = expreStmt; //pointer to expreStmt struct in AST
return n;
}
How can I manage type checking (between VariableName and ExpressionStatement)? Have I to create a function with the entire AST like parameter (in ast.c) or have I to call this function whenever I find a production that requires type checking in the parser ?