aboutsummaryrefslogtreecommitdiffstats
path: root/syntax.h
diff options
context:
space:
mode:
Diffstat (limited to 'syntax.h')
-rw-r--r--syntax.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/syntax.h b/syntax.h
new file mode 100644
index 0000000..9f2d224
--- /dev/null
+++ b/syntax.h
@@ -0,0 +1,123 @@
+#ifndef __SYNTAX_H
+#define __SYNTAX_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+
+#include "debug.h"
+#include "tokenizer.h"
+
+#define ALLOC_MEMSET(T,VAL) {VAL=malloc(sizeof(T));memset(VAL,0,sizeof(T));}
+
+
+typedef struct ast_range ast_range;
+typedef struct ast_if ast_if;
+typedef struct ast_value ast_value;
+typedef struct ast_expr ast_expr;
+typedef struct ast_expr_bit ast_expr_bit;
+typedef struct ast_expr_cmp ast_expr_cmp;
+
+//welcome to 90's
+//[TYPE]_[SET/GET/ADD/INIT]_[VALUE]
+//G -get
+//S -set
+//A - add
+//I - init
+//SZ-size
+//S - start
+//E - end
+
+//ATRT
+typedef struct ast_root
+{
+ int size;
+ int total_tokens;
+ ast_range **range;
+} ast_root;
+
+//ATRN
+typedef struct ast_range
+{
+ int range_type;
+ unsigned long start;
+ unsigned long end;
+ int next_type;
+ int size_iff;
+ ast_if **iff;
+ ast_value *val;
+} ast_range;
+
+//ATI
+typedef struct ast_if
+{
+ int eval;
+ ast_expr *expr;
+ ast_value *val;
+} ast_if;
+
+//ATEB
+typedef struct ast_expr_bit
+{
+ unsigned char mask;
+} ast_expr_bit;
+
+//ATEC
+typedef struct ast_expr_cmp
+{
+ unsigned char val;
+} ast_expr_cmp;
+
+//ATE
+typedef struct ast_expr
+{
+ int type;
+ int size_cmp;
+ int size_bit;
+ ast_expr_cmp **cmp;
+ ast_expr_bit **bit;
+} ast_expr;
+
+//ATV
+typedef struct ast_value
+{
+ int size;
+ char *note;
+
+} ast_value;
+
+static int tk_pos = 0;
+
+ast_root* ast_syntax( token_list *tl );
+ast_if* att_if( token_list *tl, int pos );
+ast_range* att_range( token_list *tl, int pos );
+ast_expr* att_expr( token_list *tl, int pos );
+ast_expr_cmp* att_expr_cmp( token_list *tl, int pos );
+ast_expr_bit* att_expr_bit( token_list *tl, int pos );
+ast_value* att_value( token_list *tl, int pos );
+ast_root* atrt_i();
+int atrt_a_range( ast_root **rt, ast_range *rng, int idx);
+ast_range* atrn_i();
+int atrn_a_if( ast_range **rng, ast_if *iff );
+int atrn_a_val( ast_range **rng, ast_value *val );
+int atrn_s_rng0( ast_range **rng, int value );
+int atrn_s_rng1( ast_range **rng, unsigned long start, unsigned long end);
+int atrn_s_val( ast_range **rng, ast_value *val );
+ast_if* ati_i();
+int ati_s_expr( ast_if **iff, ast_expr *expr );
+int ati_s_val( ast_if **iff, ast_value *val );
+ast_expr* ate_i();
+int ate_a_bit( ast_expr **expr, ast_expr_bit *bit );
+int ate_a_cmp( ast_expr **expr, ast_expr_cmp *cmp );
+int ate_eval( ast_expr *expr );
+ast_expr_bit* ateb_i();
+int ateb_s_mask( ast_expr_bit **expr, unsigned char mask );
+ast_expr_cmp* atec_i();
+int atec_s_val( ast_expr_cmp **expr, unsigned char val );
+ast_value* atv_i();
+int atv_s_note( ast_value **val, char *note, int size);
+int print_ast( ast_root *root );
+
+#endif \ No newline at end of file