diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-20 10:29:33 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-20 10:29:33 +0200 |
commit | 3829a704150a06b2767d542b39179377a592da0f (patch) | |
tree | 316a1e01f3306d717739e6d73b25f5215c2cf8f0 /include | |
parent | cc383b7b2d89f05b724460b4d5cb385525911671 (diff) | |
download | imp-3829a704150a06b2767d542b39179377a592da0f.tar.gz imp-3829a704150a06b2767d542b39179377a592da0f.zip |
folder structure
Diffstat (limited to 'include')
-rw-r--r-- | include/ast.h | 44 | ||||
-rw-r--r-- | include/hash_map.h | 12 | ||||
-rw-r--r-- | include/interpreter.h | 17 |
3 files changed, 73 insertions, 0 deletions
diff --git a/include/ast.h b/include/ast.h new file mode 100644 index 0000000..9c6b6bd --- /dev/null +++ b/include/ast.h @@ -0,0 +1,44 @@ +#ifndef AST_H +#define AST_H + +typedef enum { + NT_SKIP, NT_ASSIGN, NT_SEQ, NT_IF, NT_WHILE, + NT_INT, NT_VAR, NT_AOP, NT_BOP, NT_NOT, NT_ROP +} NodeType; + +typedef enum { AOP_ADD, AOP_SUB, AOP_MUL } AOp; +typedef enum { BOP_AND, BOP_OR } BOp; +typedef enum { ROP_EQ, ROP_NE, ROP_LT, ROP_LE, ROP_GT, ROP_GE } ROp; + +typedef struct ASTNode { + NodeType type; + union { + struct { struct ASTNode *var, *aexp; } d_assign; + struct { struct ASTNode *stm1, *stm2; } d_seq; + struct { struct ASTNode *bexp, *stm1, *stm2; } d_if; + struct { struct ASTNode *bexp, *stm; } d_while; + struct { int val; } d_int ; + struct { char *name; } d_var; + struct { AOp aop; struct ASTNode *aexp1, *aexp2; } d_aop; + struct { BOp bop; struct ASTNode *bexp1, *bexp2; } d_bop; + struct { struct ASTNode *bexp; } d_not; + struct { ROp rop; struct ASTNode *aexp1, *aexp2; } d_rop; + } u; +} ASTNode; + +ASTNode *ast_skip(void); +ASTNode *ast_assign(ASTNode *var, ASTNode *aexp); +ASTNode *ast_seq(ASTNode *stm1, ASTNode *stm2); +ASTNode *ast_if(ASTNode *bexp, ASTNode *stm1, ASTNode *stm2); +ASTNode *ast_while(ASTNode *bexp, ASTNode *stm); +ASTNode *ast_int(int val); +ASTNode *ast_var(char *name); +ASTNode *ast_aop(AOp aop, ASTNode *aexp1, ASTNode *aexp2); +ASTNode *ast_bop(BOp bop, ASTNode *bexp1, ASTNode *bexp2); +ASTNode *ast_not(ASTNode *bexp); +ASTNode *ast_rop(ROp rop, ASTNode *aexp1, ASTNode *aexp2); + +void free_ast(ASTNode *node); + +#endif + diff --git a/include/hash_map.h b/include/hash_map.h new file mode 100644 index 0000000..ad873f8 --- /dev/null +++ b/include/hash_map.h @@ -0,0 +1,12 @@ +#ifndef HASH_MAP_H +#define HASH_MAP_H + +typedef void *hashmap_t; + +hashmap_t hashmap_create(void); +void hashmap_insert(hashmap_t map, const char *key, int value); +int *hashmap_get(hashmap_t map, const char *key); +void hashmap_delete(hashmap_t map, const char *key); +void hashmap_free(hashmap_t map); + +#endif
\ No newline at end of file diff --git a/include/interpreter.h b/include/interpreter.h new file mode 100644 index 0000000..182f2e5 --- /dev/null +++ b/include/interpreter.h @@ -0,0 +1,17 @@ +#ifndef INTERPRETER_H +#define INTERPRETER_H + +#include "ast.h" + + +typedef struct Env { + char *name; + int val; + struct Env *next; +} Env; + +void exec_stmt(Env **env, ASTNode *node); +void env_print(Env *env); + + +#endif
\ No newline at end of file |