| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #ifndef _PLY_NODE_H
- #define _PLY_NODE_H
- #include <stdint.h>
- 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;
- union {
- atom_t atom;
- expr_t expr;
- };
- };
- int node_walk(node_t *n,
- int (*pre)(node_t *, void *),
- int (*post)(node_t *, void *),
- 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 */
|