2024-04-30 12:01:00 +00:00
|
|
|
#include <ast/ast.h>
|
|
|
|
#include <stdio.h>
|
2024-04-12 15:28:20 +00:00
|
|
|
#include <stdlib.h>
|
2024-04-12 15:24:12 +00:00
|
|
|
#include <sys/log.h>
|
2024-02-04 15:23:32 +00:00
|
|
|
|
2024-04-12 15:24:12 +00:00
|
|
|
#define LOG_LEVEL LOG_LEVEL_DEBUG
|
|
|
|
|
2024-04-26 14:21:54 +00:00
|
|
|
extern FILE* yyin;
|
|
|
|
|
2024-04-12 15:29:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Log a debug message to inform about beginning exit procedures
|
|
|
|
*
|
|
|
|
*/
|
2024-04-12 15:28:20 +00:00
|
|
|
void notify_exit(void)
|
|
|
|
{
|
|
|
|
DEBUG("Exiting gemstone...");
|
|
|
|
}
|
|
|
|
|
2024-04-23 13:27:11 +00:00
|
|
|
/**
|
|
|
|
* @brief Closes File after compiling.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-04-26 14:21:54 +00:00
|
|
|
void close_file(void)
|
2024-04-23 13:27:11 +00:00
|
|
|
{
|
2024-04-26 14:21:54 +00:00
|
|
|
if (NULL != yyin)
|
|
|
|
{
|
|
|
|
fclose(yyin);
|
|
|
|
}
|
2024-04-23 13:27:11 +00:00
|
|
|
}
|
|
|
|
|
2024-04-12 15:29:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Run compiler setup here
|
|
|
|
*
|
|
|
|
*/
|
2024-04-12 15:24:12 +00:00
|
|
|
void setup(void)
|
|
|
|
{
|
2024-04-12 15:29:39 +00:00
|
|
|
// setup preample
|
|
|
|
|
2024-04-12 15:24:12 +00:00
|
|
|
log_init();
|
|
|
|
DEBUG("starting gemstone...");
|
|
|
|
|
2024-04-12 15:28:20 +00:00
|
|
|
#if LOG_LEVEL <= LOG_LEVEL_DEBUG
|
|
|
|
atexit(¬ify_exit);
|
|
|
|
#endif
|
|
|
|
|
2024-04-12 15:29:39 +00:00
|
|
|
// actual setup
|
2024-04-22 11:41:37 +00:00
|
|
|
|
2024-04-12 15:24:12 +00:00
|
|
|
DEBUG("finished starting up gemstone...");
|
2024-04-22 11:41:37 +00:00
|
|
|
}
|
|
|
|
|
2024-04-23 12:25:49 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
2024-04-12 15:24:12 +00:00
|
|
|
setup();
|
2024-04-26 14:21:54 +00:00
|
|
|
atexit(close_file);
|
2024-04-25 12:02:12 +00:00
|
|
|
|
2024-04-23 12:25:49 +00:00
|
|
|
// Check for file input as argument
|
|
|
|
if (2 != argc)
|
|
|
|
{
|
2024-04-23 13:27:11 +00:00
|
|
|
INFO("Usage: %s <filename>\n", argv[0]);
|
2024-04-23 12:25:49 +00:00
|
|
|
PANIC("No File could be found");
|
|
|
|
}
|
2024-04-21 20:48:29 +00:00
|
|
|
|
2024-04-23 12:25:49 +00:00
|
|
|
// filename as first argument
|
|
|
|
char *filename = argv[1];
|
|
|
|
|
2024-04-26 14:21:54 +00:00
|
|
|
FILE *file = fopen(filename, "r");
|
|
|
|
|
2024-04-30 12:01:00 +00:00
|
|
|
struct AST_Node_t* node = AST_new_node(AST_Branch, NULL);
|
|
|
|
|
|
|
|
struct AST_Node_t* child = AST_new_node(AST_OperatorAdd, NULL);
|
|
|
|
AST_push_node(child, AST_new_node(AST_IntegerLiteral, "43"));
|
|
|
|
AST_push_node(child, AST_new_node(AST_IntegerLiteral, "9"));
|
|
|
|
|
|
|
|
AST_push_node(node, child);
|
|
|
|
AST_push_node(node, AST_new_node(AST_Expression, NULL));
|
|
|
|
AST_push_node(node, AST_new_node(AST_Expression, NULL));
|
|
|
|
|
|
|
|
FILE* out = fopen("ast.gv", "w+");
|
|
|
|
// convert this file ^^^^^^
|
|
|
|
// to an svg with: `dot -Tsvg ast.gv > graph.svg`
|
|
|
|
|
|
|
|
AST_fprint_graphviz(out, node);
|
|
|
|
|
|
|
|
AST_delete_node(node);
|
|
|
|
|
|
|
|
fflush(out);
|
|
|
|
fclose(out);
|
2024-04-22 10:53:48 +00:00
|
|
|
|
2024-02-04 15:23:32 +00:00
|
|
|
return 0;
|
2024-04-12 16:20:18 +00:00
|
|
|
}
|