aboutsummaryrefslogtreecommitdiffstats
path: root/print.c
diff options
context:
space:
mode:
Diffstat (limited to 'print.c')
-rw-r--r--print.c223
1 files changed, 220 insertions, 3 deletions
diff --git a/print.c b/print.c
index a9ec939..614a6c9 100644
--- a/print.c
+++ b/print.c
@@ -9,9 +9,6 @@ void print_keyword_enum(enum Keyword code)
case KW_MACHINE:
printf("KW_MACHINE");
break;
- case KW_STATE:
- printf("KW_STATE");
- break;
case KW_FROM:
printf("KW_FROM");
break;
@@ -48,6 +45,24 @@ void print_keyword_enum(enum Keyword code)
case KW_STARTING:
printf("KW_STARTING");
break;
+ case KW_STATES:
+ printf("KW_STATES");
+ break;
+ case KW_EVENTS:
+ printf("KW_EVENTS");
+ break;
+ case KW_EVENT:
+ printf("KW_EVENT");
+ break;
+ case KW_TRANSITIONS:
+ printf("KW__TRANSITIONS");
+ break;
+ case KW_EXECUTE:
+ printf("KW_EXECUTE");
+ break;
+ case KW_COMMA:
+ printf("KW_COMMA");
+ break;
default:
printf("LEXERROR");
}
@@ -55,6 +70,7 @@ void print_keyword_enum(enum Keyword code)
void print_token(struct token *token)
{
size_t i;
+ assert(token);
printf("[ ");
print_keyword_enum(token->type);
@@ -67,11 +83,212 @@ void print_token(struct token *token)
void print_tokens(struct Queue *tokens)
{
struct Queue_Node *it;
+ assert(tokens);
+
for(it=tokens->first;it!=NULL;it=it->prev)
{
print_token( (struct token*)(it->data));
printf(" ");
}
}
+void print_ast_enum(enum AST_Type type)
+{
+ switch(type)
+ {
+ case AST_TYPE_MACHINE:
+ printf("AST_TYPE_MACHINE");
+ break;
+ case AST_TYPE_STATE:
+ printf("AST_TYPE_STATE");
+ break;
+ case AST_TYPE_STATES:
+ printf("AST_TYPE_STATES");
+ break;
+ case AST_TYPE_EVENT:
+ printf("AST_TYPE_EVENT");
+ break;
+ case AST_TYPE_EVENTS:
+ printf("AST_TYPE_EVENTS");
+ break;
+ case AST_TYPE_TRANSITION:
+ printf("AST_TYPE_TRANSITION");
+ break;
+ case AST_TYPE_TRANSITIONS:
+ printf("AST_TYPE_TRANSITIONS");
+ break;
+ case AST_TYPE_COMMAND:
+ printf("AST_TYPE_COMMAND");
+ break;
+ case AST_TYPE_PIPELINE:
+ printf("AST_TYPE_PIPELINE");
+ break;
+ default:
+ printf("AST_NOP");
+ }
+
+}
+void print_ast(struct AST *tree)
+{
+ assert(tree);
+
+ switch(tree->type)
+ {
+ case AST_TYPE_MACHINE:
+ print_ast_machine((struct AST_Machine*)tree);
+ break;
+ case AST_TYPE_STATE:
+ print_ast_state((struct AST_State*)tree);
+ break;
+ case AST_TYPE_STATES:
+ print_ast_states((struct AST_States*)tree);
+ break;
+ case AST_TYPE_EVENT:
+ print_ast_event((struct AST_Event*)tree);
+ break;
+ case AST_TYPE_EVENTS:
+ print_ast_events((struct AST_Events*)tree);
+ break;
+ case AST_TYPE_TRANSITION:
+ print_ast_transition((struct AST_Transition*)tree);
+ break;
+ case AST_TYPE_TRANSITIONS:
+ print_ast_transitions((struct AST_Transitions*)tree);
+ break;
+ case AST_TYPE_COMMAND:
+ print_ast_command((struct AST_Command*)tree);
+ break;
+ case AST_TYPE_PIPELINE:
+ print_ast_pipeline((struct AST_Pipeline*)tree);
+ break;
+ default:
+ printf("noast");
+ }
+}
+void print_ast_state(struct AST_State* tree)
+{
+ assert(tree);
+
+ printf("[ STATE: ");
+ print_ast_enum(tree->type);
+ printf("]");
+}
+void print_ast_event(struct AST_Event* tree)
+{
+ assert(tree);
+
+ printf("[ EVENT: ");
+ print_ast_enum(tree->type);
+ printf("]");
+}
+void print_ast_states(struct AST_States* tree)
+{
+ size_t i;
+ assert(tree);
+
+ printf("STATES [\n");
+ for(i=0;i<tree->number_of_states;++i)
+ {
+ print_ast_state(tree->states[i]);
+ printf(" ");
+ }
+ printf("\n ] END STATES \n");
+}
+void print_ast_events(struct AST_Events* tree)
+{
+ size_t i;
+ assert(tree);
+ printf("EVENTS [\n");
+ for(i=0;i<tree->number_of_events;++i)
+ {
+ print_ast_event(tree->events[i]);
+ printf(" ");
+ }
+ printf("\n ] END EVENTS \n");
+}
+void print_ast_transition(struct AST_Transition* tree)
+{
+ assert(tree);
+
+ printf("TRANSITION [\nFROM");
+ print_ast_state(tree->from);
+ printf(" TO ");
+ print_ast_state(tree->to);
+ printf(" COMMAND {");
+ if(tree->pipeline==NULL)
+ {
+ printf("NULL");
+ }else
+ {
+ print_ast_pipeline(tree->pipeline);
+ }
+
+}
+void print_ast_command(struct AST_Command* tree)
+{
+ assert(tree);
+
+ printf("( command ");
+ print_token(tree->function_name);
+ if(tree->argument==NULL)
+ {
+ printf(" NOARGUMENTS ");
+ }else
+ {
+ printf(" \"");
+ print_token(tree->argument);
+ printf("\" ");
+ }
+ printf(")");
+}
+void print_ast_pipeline(struct AST_Pipeline* tree)
+{
+ size_t i;
+ assert(tree);
+ printf("PIPELINE <");
+ for(i=0;i<tree->size;++i)
+ {
+ print_ast_command(tree->pipeline[i]);
+ printf(" | ");
+ }
+ printf("> PIPELINE_END");
+}
+void print_ast_machine(struct AST_Machine* tree)
+{
+ assert(tree);
+ printf("MACHINE ");
+ print_token(tree->id);
+ printf(" [\n");
+ print_ast_states(tree->states);
+ print_ast_events(tree->events);
+ print_ast_transitions(tree->transitions);
+ printf("] MACHINE_END\n");
+}
+void print_ast_transitions(struct AST_Transitions* tree)
+{
+ size_t i;
+ assert(tree);
+ printf("TRANSITIONS [\n");
+ for(i=0;i<tree->size;++i)
+ {
+ print_ast_transition(tree->transitions[i]);
+ printf("\n");
+ }
+ printf("] TRANSITIONS_END\n");
+}
+void print_error(struct Error *error)
+{
+ assert(error);
+ printf("Error: %s, line %ld row %ld\n",error->message,error->row,error->column);
+}
+void print_errors(struct Translation_Data *translation_data)
+{
+ struct Queue_Node *it;
+ assert(translation_data);
+
+ for(it=translation_data->errors->first;it!=NULL;it=it->prev)
+ {
+ print_error(it->data);
+ }
+}
#endif