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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
#ifndef PARSER_H
#define PARSER_H PARSER_H
#include <program.h>
#include <stddef.h>
#include <assert.h>
#include <map.h>
#define AS_BIN_EXPR_PTR(x) ((struct AST_Binary_Expression*)x)
#define AS_UN_EXPR_PTR(x) ((struct AST_Unary_Expression*)x)
#define AS_UNCK_EXPR_PTR(x) ((struct AST_Unchecked_State*)x)
enum AST_Type
{
AST_TYPE_TRANSLATION_UNIT,
AST_TYPE_MACHINE,
AST_TYPE_STATE,
AST_TYPE_STATES,
AST_TYPE_EVENT,
AST_TYPE_EVENTS,
AST_TYPE_TRANSITION,
AST_TYPE_TRANSITIONS,
AST_TYPE_COMMAND,
AST_TYPE_PIPELINE,
AST_TYPE_OP_AND,
AST_TYPE_OP_OR,
AST_TYPE_OP_NOT,
AST_TYPE_OP_SELECTOR,
AST_TYPE_UNFINISHED_STATE,
};
struct AST
{
enum AST_Type type;
};
struct AST_State
{
struct token *name;
size_t number;
};
struct AST_Event
{
struct token *name;
};
struct AST_States
{
enum AST_Type type;
size_t number_of_states;
struct Map *states_map;
struct AST_State *states[];
};
struct AST_Events
{
enum AST_Type type;
size_t number_of_events;
struct Map *events_map;
struct AST_Event *events[];
};
struct AST_Transition
{
enum AST_Type type;
struct AST *from;
struct AST_State *to;
struct AST_Event *event;
struct AST_Pipeline *pipeline;
};
struct AST_Command
{
enum AST_Type type;
struct token *function_name;
struct token *argument;
};
struct AST_Pipeline
{
enum AST_Type type;
size_t size;
struct AST_Command *pipeline[];
};
struct AST_Transitions
{
enum AST_Type type;
size_t size;
struct AST_Transition *transitions[];
};
struct AST_Machine
{
enum AST_Type type;
struct token *id;
struct AST_State *starting_state;
struct AST_States *states;
struct AST_Events *events;
struct AST_Transitions *transitions;
};
struct AST_Translation_Unit
{
enum AST_Type type;
struct Map *used_commands_map;
struct Map *machines_map;
size_t number_of_machines;
struct AST_Machine *machines[];
};
struct AST_Binary_Expression
{
enum AST_Type type;
struct AST *left;
struct AST *right;
};
struct AST_Unary_Expression
{
enum AST_Type type;
struct AST *operand;
};
struct AST_Unchecked_State
{
enum AST_Type type;
struct token *name;
};
struct AST* parse_source(struct Translation_Data *translation_data);
struct AST_Translation_Unit* parse_translation_unit(struct Translation_Data *translation_data);
struct AST_Machine* parse_machine(struct Translation_Data *translation_data);
struct AST_Machine* parse_machine_inner(struct token *machine_id,struct Translation_Data *translation_data);
struct AST_States* parse_states_inner(struct Translation_Data *translation_data);
struct AST_State* parse_state(struct Translation_Data *translation_data);
struct AST_Events* parse_events_inner(struct Translation_Data *translation_data);
struct AST_Event* parse_event(struct Translation_Data *translation_data);
struct AST_Transitions* parse_transitions_inner(struct Translation_Data *translation_data,struct AST_States *states,struct AST_Events *events );
struct AST_Transition* parse_transition(struct Translation_Data *translation_data,struct AST_States *states,struct AST_Events *events);
struct AST_Pipeline* parse_pipeline(struct Translation_Data *translation_data);
struct AST_Command* parse_command(struct Translation_Data *translation_data);
struct AST_State* parse_start_on(struct Translation_Data *translation_data,struct AST_States *states);
struct AST* parse_expression(struct Translation_Data *translation_data);
struct AST* parse_or_expression(struct Translation_Data *translation_data);
struct AST* parse_and_expression(struct Translation_Data *translation_data);
struct AST* parse_not_expression(struct Translation_Data *translation_data);
struct AST* parse_primary_expression(struct Translation_Data *translation_data);
struct AST_State* get_ast_state(struct token *id);
struct AST_Event* get_ast_event(struct token *id);
struct AST_States* get_ast_states(struct Queue *states);
struct AST_Events* get_ast_events(struct Queue *events);
struct AST_Transition* get_ast_transition(struct AST *from,struct AST_State *to,struct AST_Event *event,struct AST_Pipeline *pipeline);
struct AST_Command* get_ast_command(struct token *function_name,struct token *argument);
struct AST_Pipeline* get_ast_pipeline(struct Queue *pipeline);
struct AST_Machine* get_ast_machine(struct token *id,struct AST_States *states,struct AST_Events *events,struct AST_Transitions *transitions,struct AST_State *starting_state);
struct AST_Transitions* get_ast_transitions(struct Queue *transitions);
struct AST_Translation_Unit* get_ast_translation_unit(struct Queue *machines,struct Map *command_map,struct Map *machines_map);
struct AST_Binary_Expression* get_ast_binary_expression(struct AST *left,struct AST *right,enum AST_Type type);
struct AST_Unary_Expression* get_ast_unary_expression(struct AST *operand,enum AST_Type type);
struct AST_Unchecked_State* get_ast_unchecked_state(struct token *name);
struct AST_State* ast_check_state(struct AST_Unchecked_State *state,struct AST_States *states,struct Translation_Data *translation_data);
void delete_ast(struct AST* ast);
void delete_ast_event(struct AST_Event* ast);
void delete_ast_states(struct AST_States* ast);
void delete_ast_state(struct AST_State* ast);
void delete_ast_events(struct AST_Events* ast);
void delete_ast_transition(struct AST_Transition* ast);
void delete_ast_command(struct AST_Command* ast);
void delete_ast_pipeline(struct AST_Pipeline* ast);
void delete_ast_machine(struct AST_Machine* ast);
void delete_ast_transitions(struct AST_Transitions* ast);
void delete_ast_translation_unit(struct AST_Translation_Unit *ast);
void delete_ast_binary_expression(struct AST_Binary_Expression *ast);
void delete_ast_unary_expression(struct AST_Unary_Expression *ast);
void delete_ast_unchecked_state(struct AST_Unchecked_State *ast);
void pointer_array_fill(void **array,struct Queue *q);
struct Queue* parse_list(struct AST *(*parser)(struct Translation_Data*),struct Translation_Data *translation_data,enum Keyword delim);
#endif
|