aboutsummaryrefslogtreecommitdiff
path: root/src/ast.h
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2021-09-24 16:42:54 +0900
committerShinya Sato <shinnya.sato@gmail.com>2021-09-24 16:42:54 +0900
commit6b3075d90d945d5e7e8fd4d28284ffd99dbeb82e (patch)
tree4d9e58166e36452bc3a19172d9cfb7a245f996b0 /src/ast.h
parentdd62122ee43d2c388fb96518eaa527976fddfc38 (diff)
downloadinpla-6b3075d90d945d5e7e8fd4d28284ffd99dbeb82e.tar.gz
inpla-6b3075d90d945d5e7e8fd4d28284ffd99dbeb82e.zip
v0.4.1
Diffstat (limited to 'src/ast.h')
-rw-r--r--src/ast.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/ast.h b/src/ast.h
new file mode 100644
index 0000000..0acc5bb
--- /dev/null
+++ b/src/ast.h
@@ -0,0 +1,62 @@
+// http://www.hpcs.cs.tsukuba.ac.jp/~msato/lecture-note/comp-lecture/tiny-c/AST.h
+
+#ifndef _AST_
+#define _AST_
+
+typedef enum {
+ AST_SYM=0, AST_NAME, AST_INTVAR, AST_AGENT, AST_CNCT, AST_RULE,
+ AST_BODY, AST_IF, AST_THEN_ELSE,
+
+ // this is for ASTLIST
+ AST_LIST,
+
+ // annotation
+ AST_ANNOTATION_L, AST_ANNOTATION_R,
+
+ // builtin tuble
+ AST_TUPLE,
+
+ // operation
+ AST_INT, AST_LD, AST_PLUS, AST_SUB, AST_MUL, AST_DIV, AST_MOD,
+ AST_LT, AST_LE, AST_EQ, AST_NE, AST_UNM,
+
+ // for built-in lists
+ AST_CONS, AST_NIL, AST_OPCONS,
+
+ // for built-in agents
+
+ AST_RAND, AST_SRAND,
+
+} AST_ID;
+
+
+typedef struct abstract_syntax_tree {
+ AST_ID id;
+ int intval;
+ char *sym;
+ struct abstract_syntax_tree *left,*right;
+} Ast;
+
+void ast_heapInit(void);
+void ast_heapReInit(void);
+Ast *ast_makeSymbol(char *name);
+Ast *ast_makeInt(int num);
+Ast *ast_makeAST(AST_ID id, Ast *left, Ast *right);
+Ast *ast_makeTuple(Ast *tuple);
+Ast *ast_addLast(Ast *l, Ast *p);
+Ast *ast_getNth(Ast *p,int nth);
+Ast *ast_getTail(Ast *p);
+void puts_ast(Ast *p);
+Ast *ast_paramToCons(Ast *ast);
+void ast_recordConst(char *name, int val);
+Ast *ast_remove_tuple1(Ast *p);
+
+
+#define ast_makeCons(x1,x2) ast_makeAST(AST_LIST,x1,x2)
+#define ast_makeList1(x1) ast_makeAST(AST_LIST,x1,NULL)
+#define ast_makeList2(x1,x2) ast_makeAST(AST_LIST,x1,ast_makeAST(AST_LIST,x2,NULL))
+#define ast_makeList3(x1,x2,x3) ast_makeAST(AST_LIST,x1,ast_makeAST(AST_LIST,x2,ast_makeAST(AST_LIST,x3,NULL)))
+#define getFirst(p) getNth(p,0)
+
+
+#endif