12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #ifndef _PGMPREFIX_AST_NODE_H_
- #define _PGMPREFIX_AST_NODE_H_
- #include "dd_dynamic_array.h"
- /* abstract syntax tree
- * contains nodes that represent logic inside the game
- * each node has a unique "signature" (amount of children) to be considered
- * correct, and be able to parse itself properly to the target language
- */
- // ast node types
- enum AST_NODE_TYPE {
- // parent of all nodes
- AST_GAME,
- AST_EMPTY,
- // define a variable
- AST_DEFINITION,
- // assign an expression to a variable
- AST_ASSIGNMENT,
- // defining a function
- AST_FUNCTION_DEFINITION,
- AST_FUNCTION_CALL,
- AST_ARGUMENTS,
- AST_ARGUMENT,
- // symbol types
- AST_STRUCT,
- AST_STRUCT_PARENT,
- AST_GROUP,
- AST_VARTYPE_INT,
- AST_VARTYPE_FLOAT,
- AST_VARTYPE_VOID,
- AST_VARTYPE_STRUCT,
- // mathematical operators
- AST_ADDITION,
- AST_SUBSTRACTION,
- AST_MULTIPLICATION,
- AST_DIVISION,
- AST_LESS_THAN,
- AST_MORE_THAN,
- AST_EQUAL,
- AST_LESS_EQUAL,
- AST_MORE_EQUAL,
- AST_GROUP_EXPRESSIONS,
-
- /* variables - contain children that go through the struct hierarchy
- * example "this.x" results in a node AST_IDENTIFIER that points to the struct of "this" and
- * a child with another AST_IDENTIFIER that points to "x"
- */
- AST_IDENTIFIER,
- /* constants - have no children, are parsed as-is */
- AST_NUMBER,
- AST_STRING,
- AST_IF,
- };
- // Struct for a single node
- struct ast_node {
- enum AST_NODE_TYPE node_type;
- int value;
- struct dd_dynamic_array children;
- };
- // Actions
- struct ast_node *ast_create(enum AST_NODE_TYPE node_type, int value);
- void ast_child_add(struct ast_node *parent, struct ast_node *child);
- void ast_delete(struct ast_node *node);
- // Debug - Print node tree
- void ast_print(struct ast_node *node);
- int ast_push(struct ast_node *n);
- struct ast_node *ast_pop();
- #endif
|