fela

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

ast.h (1065B)


      1 #ifndef _AST_H_
      2 #define _AST_H_
      3 
      4 #include <string.h>
      5 
      6 enum expr_ops {
      7 	VALUE,
      8 	VAR,
      9 	ADD,
     10 	SUB,
     11 	DIV,
     12 	MUL,
     13 	NESTED,
     14 	FUNCTION,
     15 };
     16 
     17 enum type_types {
     18 	BASIC_T,
     19 	FUNCTION_T,
     20 	STRUCT_T,
     21 };
     22 
     23 struct ast_expr {
     24 	enum expr_ops op;
     25 	char *fn;
     26 	union {
     27 		struct {
     28 			int child_count;
     29 			struct ast_expr *children;
     30 		};
     31 		struct {	/* for function decs */
     32 			struct ast_args *args;
     33 			struct ast_exprs *exprs;
     34 			struct ast_decs *decs;
     35 		};
     36 		long value;
     37 	};
     38 };
     39 
     40 struct ast_exprs {
     41 	struct ast_exprs *exprs;
     42 	struct ast_expr *expr;
     43 };
     44 
     45 
     46 struct ast_type {
     47 	enum type_types t;
     48 	union {
     49 		struct { char *type; };	/* for basic types */
     50 		struct {	/* for structs and funcs */
     51 			struct ast_type *ret;
     52 			struct ast_args *args;
     53 		};
     54 	};
     55 };
     56 
     57 struct ast_arg {
     58 	struct ast_type *type; 
     59 	char *name;
     60 };
     61 
     62 struct ast_args {
     63 	int argc;
     64 	struct ast_arg *args;
     65 };
     66 
     67 struct ast_dec {
     68 	char *name;
     69 	struct ast_type *type;
     70 	struct ast_expr *value;
     71 };
     72 
     73 struct ast_decs {
     74 	struct ast_decs *decs;
     75 	struct ast_dec *dec;
     76 };
     77 
     78 
     79 struct ast_args *append_arg(struct ast_args *, struct ast_arg *);
     80 #endif