Geração de Código Intermediário
(Implementação)
..
.
void GenerateCode(Node * ast)
{
int i = 0;
if (ast == NULL)
return;
while (ast->children[i] != NULL)
{
GenerateCode(ast->children[i]);
i++;
}
if ((ast->type == ADD_OP) || (ast->type == SUB_OP) ||
(
ast->type == DIV_OP) || (ast->type == MULT_OP)){
if ((ast->children[0]->type == INT_LIT) &&
ast->children[1]->type == INT_LIT)){
(
printf("mov eax, %s\n", ast->children[0]->info);
printf("mov ebx, %s\n", ast->children[1]->info);
}
.
..