-
Notifications
You must be signed in to change notification settings - Fork 6
/
ast.h
87 lines (71 loc) · 1.92 KB
/
ast.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Autor: Adriano Melo <[email protected]>
* Modificado por:
*
* ast.h : escreve estruturas usadas para construir a AST.
**/
#ifndef AST_H
#define AST_H
// enum with the number identfifies for the ast nodes
enum {type_program, type_statement_list, type_attribution, type_identifier, type_expression, type_number, type_operation, type_int, type_double, type_char};
typedef struct program program_t;
typedef struct statement_list statement_list_t;
typedef struct attribution attribution_t;
typedef struct identifier identifier_t;
typedef struct type type_t;
typedef struct expression expression_t;
typedef struct number number_t;
typedef struct operation operation_t;
typedef struct ast_node ast_t;
/* node used for creating ast tree */
ast_t* root;
struct ast_node {
int node_type;
};
struct program {
int node_type;
statement_list_t* head;
statement_list_t* tail;
};
program_t* new_program();
void add_statement(program_t* program, statement_list_t* stmt);
struct statement_list {
int node_type;
ast_t* stmt;
statement_list_t* next;
};
statement_list_t* new_statement_list(ast_t* stmt);
struct attribution {
int node_type;
identifier_t* identifier;
ast_t* value; // expression, number
};
attribution_t* new_attribution(identifier_t* identifier, ast_t* expression);
struct expression {
int node_type;
ast_t* left;
ast_t* operation;
ast_t* right;
};
expression_t* new_expression(ast_t* left, ast_t* operation, ast_t* right);
struct operation {
int node_type;
char* operation;
};
operation_t* new_operation(char* operation);
struct identifier {
int node_type;
char* identifier;
};
identifier_t* new_identifier(char* identifier);
struct type {
int node_type;
char* name;
};
type_t* new_type(char* name);
struct number {
int node_type;
double value;
};
number_t* new_number(double value);
#endif