aboutsummaryrefslogblamecommitdiffstats
path: root/syntax.h
blob: a2efdfe6d1ed53d0457d3721d63a09c3584e38b9 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                      

 


                                                                            









                                   
 

                        
 



                   






















                           





















                            

                 



                          










                                                      
                                                 



















                                                                          
                                  

     
#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));}


//welcome to 90's
//[TYPE]_[SET/GET/ADD/INIT]_[VALUE]
//G -get
//S -set
//A - add
//I - init
//SZ-size
//S - start
//E - end


//ATV
typedef struct ast_value
{
	int size;
	char *note;
	
} ast_value;

//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;

//ATI
typedef struct ast_if
{
	int eval;
	ast_expr *expr;
	ast_value *val;
} ast_if;

//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;

//ATRT
typedef struct ast_root
{
	int size;
	int total_tokens;
	ast_range **range;
} ast_root;


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);
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 );
int ast_destroy( ast_root *root );

#endif