| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #ifndef _PLY_NODE_H
- #define _PLY_NODE_H
- #include <stdint.h>
- #include <stdio.h>
- #include "sym.h"
- #include "type.h"
- typedef struct node node_t;
- typedef enum keyword {
- KW_SUBSCRIPT = '[',
- KW_ASSIGN = '=',
- } keyword_t;
- typedef enum ntype {
- N_LIST,
- N_KEYWORD,
- N_IDENT,
- N_NUM,
- N_STRING,
- } ntype_t;
- struct node {
- node_t *next, *prev, *up;
- ntype_t ntype;
- union {
- node_t *list;
- keyword_t keyword;
- char *ident;
- int64_t num;
- char *string;
- };
- type_t *type;
- sym_t *sym;
- };
- /* debug */
- void node_print(node_t *n, FILE *fp);
- void node_dump (node_t *n, FILE *fp);
- typedef int (*walk_fn)(node_t *, void *);
- int node_walk(node_t *n, walk_fn pre, walk_fn post, void *ctx);
- /* constructors */
- node_t *node_list (node_t *head);
- node_t *node_vlist (node_t *head, ...);
- node_t *node_keyword(keyword_t keyword);
- node_t *node_ident (char *name);
- node_t *node_num (int64_t num);
- node_t *node_string (char *string);
- static inline node_t *node_head(node_t *n)
- {
- if (!n)
- return NULL;
- for (; n->prev; n = n->prev);
- return n;
- }
- static inline node_t *node_prev(node_t *n)
- {
- return n ? n->prev : NULL;
- }
- static inline node_t *node_next(node_t *n)
- {
- return n ? n->next : NULL;
- }
- static inline node_t *node_up(node_t *n)
- {
- return n ? n->up : NULL;
- }
- #endif /* _PLY_NODE_H */
|