| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #ifndef _PLY_NODE_H
- #define _PLY_NODE_H
- #include <stdint.h>
- typedef struct sym sym_t;
- typedef struct atom atom_t;
- typedef struct expr expr_t;
- typedef struct node node_t;
- typedef enum atype {
- A_INVALID,
- A_IDENT,
- A_NUM,
- A_STRING,
- } atype_t;
- struct atom {
- atype_t atype;
- union {
- char *ident;
- int64_t num;
- char *string;
- };
- };
- typedef enum etype {
- E_INVALID = '\0',
- E_AGG = '@',
- E_CALL = '(',
- E_DEREF = '*',
- E_DOT = '.',
- E_MAP = 'm',
- E_SCOPE = '{',
-
- } etype_t;
- struct expr {
- etype_t etype;
- node_t *arg;
- };
- typedef enum ntype {
- N_INVALID,
- N_ATOM,
- N_EXPR,
- } ntype_t;
- struct node {
- ntype_t ntype;
- node_t *up;
- node_t *next;
- sym_t *sym;
- union {
- atom_t atom;
- expr_t expr;
- };
- };
- /* walk a node tree */
- typedef int (*walk_fn)(node_t *, void *);
- int node_walk(node_t *n, walk_fn pre, walk_fn post, void *ctx);
- /* node constructors */
- node_t *node_ident (char *name);
- node_t *node_num (int64_t num);
- node_t *node_string(char *string);
- node_t *node_expr (etype_t etype, node_t *arg);
- node_t *node_cons (node_t *head, node_t *tail);
- /* debug */
- typedef struct node_dump_info {
- FILE *fp;
- int indent;
- } node_dump_info_t;
- void node_dump(node_t *n, node_dump_info_t *info);
- #endif /* _PLY_NODE_H */
|