languages/compiler/header.h

Go to the documentation of this file.
00001 
00002 typedef unsigned char byte;
00003 typedef unsigned short symbol;
00004 
00005 #define true 1
00006 #define false 0
00007 #define repeat while(true)
00008 #define unless(C) if(!(C))
00009 #define until(C) while(!(C))
00010 
00011 #define MALLOC check_malloc
00012 #define FREE check_free
00013 
00014 #define NEW(type, p) struct type * p = (struct type *) MALLOC(sizeof(struct type))
00015 #define NEWVEC(type, p, n) struct type * p = (struct type *) MALLOC(sizeof(struct type) * n)
00016 
00017 #define STARTSIZE   10
00018 #define SIZE(p)     ((int *)(p))[-1]
00019 #define CAPACITY(p) ((int *)(p))[-2]
00020 
00021 extern symbol * create_b(int n);
00022 extern void report_b(FILE * out, symbol * p);
00023 extern void lose_b(symbol * p);
00024 extern symbol * increase_capacity(symbol * p, int n);
00025 extern symbol * move_to_b(symbol * p, int n, symbol * q);
00026 extern symbol * add_to_b(symbol * p, int n, symbol * q);
00027 extern symbol * copy_b(symbol * p);
00028 extern char * b_to_s(symbol * p);
00029 extern symbol * add_s_to_b(symbol * p, const char * s);
00030 
00031 struct str; /* defined in space.c */
00032 
00033 extern struct str * str_new(void);
00034 extern void str_delete(struct str * str);
00035 extern void str_append(struct str * str, struct str * add);
00036 extern void str_append_ch(struct str * str, char add);
00037 extern void str_append_b(struct str * str, symbol * q);
00038 extern void str_append_string(struct str * str, const char * s);
00039 extern void str_append_int(struct str * str, int i);
00040 extern void str_clear(struct str * str);
00041 extern void str_assign(struct str * str, char * s);
00042 extern struct str * str_copy(struct str * old);
00043 extern symbol * str_data(struct str * str);
00044 extern int str_len(struct str * str);
00045 extern int get_utf8(const symbol * p, int * slot);
00046 extern int put_utf8(int ch, symbol * p);
00047 
00048 struct m_pair {
00049 
00050     struct m_pair * next;
00051     symbol * name;
00052     symbol * value;
00053 
00054 };
00055 
00056 struct input {
00057 
00058     struct input * next;
00059     symbol * p;
00060     int c;
00061     int line_number;
00062 
00063 };
00064 
00065 struct include {
00066 
00067     struct include * next;
00068     symbol * b;
00069 
00070 };
00071 
00072 struct tokeniser {
00073 
00074     struct input * next;
00075     symbol * p;
00076     int c;
00077     int line_number;
00078     symbol * b;
00079     symbol * b2;
00080     int number;
00081     int m_start;
00082     int m_end;
00083     struct m_pair * m_pairs;
00084     int get_depth;
00085     int error_count;
00086     int token;
00087     int previous_token;
00088     byte token_held;
00089     byte widechars;
00090     byte utf8;
00091 
00092     int omission;
00093     struct include * includes;
00094 
00095 };
00096 
00097 extern symbol * get_input(symbol * p);
00098 extern struct tokeniser * create_tokeniser(symbol * b);
00099 extern int read_token(struct tokeniser * t);
00100 extern byte * name_of_token(int code);
00101 extern void close_tokeniser(struct tokeniser * t);
00102 
00103 enum token_codes {
00104 
00105 #include "syswords2.h"
00106 
00107     c_mathassign,
00108     c_name,
00109     c_number,
00110     c_literalstring,
00111     c_neg,
00112     c_call,
00113     c_grouping,
00114     c_booltest
00115 };
00116 
00117 extern int space_count;
00118 extern void * check_malloc(int n);
00119 extern void check_free(void * p);
00120 
00121 struct node;
00122 
00123 struct name {
00124 
00125     struct name * next;
00126     symbol * b;
00127     int type;                   /* t_string etc */
00128     int mode;                   /*    )_  for routines, externals */
00129     struct node * definition;   /*    )                           */
00130     int count;                  /* 0, 1, 2 for each type */
00131     int among_func_count;       /* 1, 2, 3 for routines called by among */
00132     struct grouping * grouping; /* for grouping names */
00133     byte referenced;
00134     byte used;
00135     byte routine_called_from_among; /* used in routine definitions */
00136 
00137 };
00138 
00139 struct literalstring {
00140 
00141     struct literalstring * next;
00142     symbol * b;
00143 
00144 };
00145 
00146 struct amongvec {
00147 
00148     symbol * b;      /* the string giving the case */
00149     int size;        /* - and its size */
00150     struct node * p; /* the corresponding command */
00151     int i;           /* the amongvec index of the longest substring of b */
00152     int result;      /* the numeric result for the case */
00153     struct name * function;
00154 
00155 };
00156 
00157 struct among {
00158 
00159     struct among * next;
00160     struct amongvec * b;      /* pointer to the amongvec */
00161     int number;               /* amongs are numbered 0, 1, 2 ... */
00162     int literalstring_count;  /* in this among */
00163     int command_count;        /* in this among */
00164     int have_funcs;           /* does this among have any funcs? */
00165     struct node * starter;    /* i.e. among( (starter) 'string' ... ) */
00166     struct node * substring;  /* i.e. substring ... among ( ... ) */
00167 };
00168 
00169 struct grouping {
00170 
00171     struct grouping * next;
00172     int number;               /* groupings are numbered 0, 1, 2 ... */
00173     symbol * b;               /* the characters of this group */
00174     int largest_ch;           /* character with max code */
00175     int smallest_ch;          /* character with min code */
00176     byte no_gaps;             /* not used in generator.c after 11/5/05 */
00177     struct name * name;       /* so g->name->grouping == g */
00178 };
00179 
00180 struct node {
00181 
00182     struct node * next;
00183     struct node * left;
00184     struct node * aux;     /* used in setlimit */
00185     struct among * among;  /* used in among */
00186     struct node * right;
00187     int type;
00188     int mode;
00189     struct node * AE;
00190     struct name * name;
00191     symbol * literalstring;
00192     int number;
00193     int line_number;
00194     int amongvar_needed;   /* used in routine definitions */
00195 };
00196 
00197 enum name_types {
00198 
00199     t_size = 6,
00200 
00201     t_string = 0, t_boolean = 1, t_integer = 2, t_routine = 3, t_external = 4,
00202     t_grouping = 5
00203 
00204 /*  If this list is extended, adjust wvn in generator.c  */
00205 };
00206 
00207 /*  In name_count[i] below, remember that
00208     type   is
00209     ----+----
00210       0 |  string
00211       1 |  boolean
00212       2 |  integer
00213       3 |  routine
00214       4 |  external
00215       5 |  grouping
00216 */
00217 
00218 struct analyser {
00219 
00220     struct tokeniser * tokeniser;
00221     struct node * nodes;
00222     struct name * names;
00223     struct literalstring * literalstrings;
00224     int mode;
00225     byte modifyable;          /* false inside reverse(...) */
00226     struct node * program;
00227     struct node * program_end;
00228     int name_count[t_size];   /* name_count[i] counts the number of names of type i */
00229     struct among * amongs;
00230     struct among * amongs_end;
00231     int among_count;
00232     int amongvar_needed;      /* used in reading routine definitions */
00233     struct grouping * groupings;
00234     struct grouping * groupings_end;
00235     struct node * substring;  /* pending 'substring' in current routine definition */
00236     byte utf8;
00237 };
00238 
00239 enum analyser_modes {
00240 
00241     m_forward = 0, m_backward /*, m_integer */
00242 
00243 };
00244 
00245 extern void print_program(struct analyser * a);
00246 extern struct analyser * create_analyser(struct tokeniser * t);
00247 extern void close_analyser(struct analyser * a);
00248 
00249 extern void read_program(struct analyser * a);
00250 
00251 struct generator {
00252 
00253     struct analyser * analyser;
00254     struct options * options;
00255     int unreachable;           /* 0 if code can be reached, 1 if current code
00256                                 * is unreachable. */
00257     int var_number;            /* Number of next variable to use. */
00258     struct str * outbuf;       /* temporary str to store output */
00259     struct str * declarations; /* str storing variable declarations */
00260     int next_label;
00261     int margin;
00262 
00263     int failure_keep_count;    /* if > 0, keep_count to restore in case of a failure; if < 0, the negated keep_count for the limit to restore in case of failure. */
00264 #ifndef DISABLE_JAVA
00265     struct str * failure_str;  /* This is used by the java generator. */
00266 #endif
00267 
00268     int label_used;     /* Keep track of whether the failure label is used. */
00269     int failure_label;
00270     int debug_count;
00271 
00272     const char * S[10];  /* strings */
00273     symbol * B[10];      /* blocks */
00274     int I[10];           /* integers */
00275     struct name * V[5];  /* variables */
00276     symbol * L[5];       /* literals, used in formatted write */
00277 
00278     int line_count;      /* counts number of lines output */
00279     int line_labelled;   /* in ANSI C, will need extra ';' if it is a block end */
00280     int literalstring_count;
00281     int keep_count;      /* used to number keep/restore pairs to avoid compiler warnings about shadowed variables */
00282 };
00283 
00284 struct options {
00285 
00286     /* for the command line: */
00287 
00288     char * output_file;
00289     char * name;
00290     FILE * output_c;
00291     FILE * output_h;
00292 #ifndef DISABLE_JAVA
00293     FILE * output_java;
00294 #endif
00295     byte syntax_tree;
00296     byte widechars;
00297     enum { LANG_JAVA, LANG_C, LANG_CPLUSPLUS } make_lang;
00298     char * externals_prefix;
00299     char * variables_prefix;
00300     char * runtime_path;
00301     char * parent_class_name;
00302     struct include * includes;
00303     struct include * includes_end;
00304     byte utf8;
00305 };
00306 
00307 /* Generator for C code. */
00308 extern struct generator * create_generator_c(struct analyser * a, struct options * o);
00309 extern void close_generator_c(struct generator * g);
00310 
00311 extern void generate_program_c(struct generator * g);
00312 
00313 #ifndef DISABLE_JAVA
00314 /* Generator for Java code. */
00315 extern struct generator * create_generator_java(struct analyser * a, struct options * o);
00316 extern void close_generator_java(struct generator * g);
00317 
00318 extern void generate_program_java(struct generator * g);
00319 #endif

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.