aboutsummaryrefslogtreecommitdiff
path: root/ast.h
diff options
context:
space:
mode:
authorTeddy <ted.sybil@gmail.com>2014-03-24 12:40:12 +0800
committerTeddy <ted.sybil@gmail.com>2014-03-24 12:40:12 +0800
commitccab148f1310b3cadffb99005941e39fa932d295 (patch)
tree114ec338d11d7d691769138defafe9570d1caa5f /ast.h
parent4edd0c4745ed0683867b116dc8ac33c65bf0b99a (diff)
AST construction for expressions
Diffstat (limited to 'ast.h')
-rw-r--r--ast.h37
1 files changed, 33 insertions, 4 deletions
diff --git a/ast.h b/ast.h
index f6db7da..d438b92 100644
--- a/ast.h
+++ b/ast.h
@@ -1,7 +1,17 @@
-typedef struct {
+#ifndef AST_H
+#define AST_H
+
+#define EXP_POSTFIX 1024
+#define POSTFIX_ARR 1025
+#define POSTFIX_CALL 1026
+#define POSTFIX_DOT 1027
+#define POSTFIX_PTR 1028
+#define EXP_CAST 1029
+
+typedef struct CNode {
enum {
/* Top Level */
- PROG = 1024, FUNC_DEF, PARAMS,
+ PROG, FUNC_DEF, PARAMS,
DECL, /* declaration */
DECLR, /* declarator */
DECLRS,
@@ -18,11 +28,17 @@ typedef struct {
CONT_STMT , BREAK_STMT, RET_STMT, /* 'continue', 'break', 'return' */
/* Expressions (expressions use their token ID to denote their types */
- EXP
+ EXP,
+ TYPE_NAME,
+ ID, /* identifier */
+ INT, /* INT_CONST */
+ CHAR,
+ STR
} type;
union {
int intval;
- char *strvar;
+ int subtype;
+ char *strval;
} rec;
struct CNode *chd, *next;
/* For error reporting */
@@ -30,3 +46,16 @@ typedef struct {
int row, col;
} loc;
} CNode;
+
+CNode *cnode_create_exp(int exp_type, int pnum, ...);
+CNode *cnode_create_type_spec(int spec_type, int pnum, ...);
+CNode *cnode_append(CNode *node, CNode *tail);
+CNode *cnode_create_identifier(char *val);
+CNode *cnode_create_int_const(int val);
+CNode *cnode_create_char_const(int val);
+CNode *cnode_create_str_const(char *val);
+CNode *cnode_debug_print(CNode *ast);
+
+extern CNode *ast_root;
+
+#endif