-
Notifications
You must be signed in to change notification settings - Fork 6
/
semantic.c
73 lines (56 loc) · 1.83 KB
/
semantic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include "semantic.h"
void* s_visit_program(program_t* programa, ... )
{
printf("[semantic] Visitando programa (%d)...\n", programa->node_type);
statement_list_t* stmt = programa->head;
while (stmt != 0) {
s_visit_statement_list (stmt);
stmt = stmt->next;
}
}
void* s_visit_statement_list (statement_list_t* stmt, ... )
{
printf("[semantic] Visitando statement list...\n");
if (stmt->stmt != 0 && stmt->stmt->node_type == type_attribution) {
s_visit_attribution ((attribution_t*) stmt->stmt);
}
}
void* switch_expression(ast_t* exp)
{
if (exp != 0) {
switch (exp->node_type){
case type_expression:
return s_visit_expression((expression_t*) exp);
break;
case type_number:
return s_visit_number((number_t*) exp);
break;
case type_identifier:
return s_visit_identifier((identifier_t*) exp);
default:
printf("[semantic] ERRO AO IDENTIFICAR EXP DA ATRIBUICAO\n");
}
}
}
void* s_visit_attribution (attribution_t* att, ... )
{
printf("[semantic] Visitando atribuicao\n");
s_visit_identifier (att->identifier);
switch_expression (att->value);
}
void* s_visit_identifier (identifier_t* id, ... )
{
printf("[semantic] Visitando identifier %s\n", id->identifier);
}
void* s_visit_expression (expression_t* exp, ... )
{
operation_t* op = (operation_t*) exp->operation;
printf("[semantic] Visitando expression %s\n", op->operation);
switch_expression (exp->right);
switch_expression (exp->left);
}
void* s_visit_number (number_t* num, ... )
{
printf("[semantic] Visitando number %f\n", num->value);
}