C:/Users/Dennis/src/lang/bertrand/BERTRAND/bertrand/def.h

Go to the documentation of this file.
00001 /* Definitions for Bertrand interpreter */
00002 
00003 /* COPYRIGHT (c) 1988  by Wm Leler, all rights reserved */
00004 /* The Bertrand Language, and this interpreter are proprietary to
00005    Wm Leler, and may not be used or copied without permission. */
00006 static char notice[] = "Copyright (c) 1988 Wm Leler";
00007 
00008 #include <stdio.h>
00009 #include <string.h>
00010 
00011 /* Location to look for #included files in */
00012 #ifndef LIBDIR
00013 #define LIBDIR  "/usr/lib/local/bertrand/"
00014 #endif
00015 
00016 #define TRUE            1
00017 #define FALSE           0
00018 #ifndef NULL
00019 #define NULL            0
00020 #endif
00021 
00022 #define BIG_LONG        2147483646      /* 2^31 - 1 */
00023 #define BIG_SHORT       32767           /* 2^15 - 1 */
00024 
00025 #define MAXTOKEN 1023           /* maximum length of an input token */
00026                                 /* including strings! */
00027 #define MAXFILES 16             /* max input files (max depth of #includes) */
00028 
00029 extern void error();    /* print error message routine, from util.c */
00030 extern int verbose;     /* print debugging info, from main.c */
00031 
00032 /* token types, returned from scan()                            */
00033 #define OPER    301     /* user defined operator                */
00034 #define NUMBER  302     /* constant number                      */
00035 #define IDENT   303     /* identifier that is not an operator   */
00036 #define STRING  304     /* character string                     */
00037 #define TYPE    305     /* type, beginning with single quote    */
00038 /* The three reserved characters {.} return as themselves.      */
00039 
00040 /* Character input classes, used by scanner.c and prep.c        */
00041 #define C_EOF   0       /* eof, null                    */
00042 #define C_CTRL  1       /* (invalid) control character  */
00043 #define C_NL    2       /* lf, cr, ff (lineno++)        */
00044 #define C_WS    3       /* blank, tab (whitespace)      */
00045 #define C_SPC   4       /* special character            */
00046 #define C_NUM   5       /* numeric 0-9                  */
00047 #define C_ALPH  6       /* alphabetic a-Z, underscore _ */
00048 #define C_PER   7       /* period . (lotsa stuff)       */
00049 #define C_DQ    8       /* double quote " (string)      */
00050 #define C_BQ    9       /* back quote ` (string escape) */
00051 #define C_SQ    10      /* single quote ' (type)        */
00052 #define C_BRC   11      /* braces { } (rule body)       */
00053 #define C_LB    12      /* pound sign # (preprocessor)  */
00054 /*  Special characters are all symbols such as + * & , etc.     */
00055 /*  They can be used in one or two character operators.         */
00056 /*  Periods are used in numbers, to connect compound names,     */
00057 /*  and to begin comments.                                      */
00058 
00059 typedef struct rule {
00060         struct rule *next;      /* next rule in hash table */
00061         struct node *head;      /* head expression */
00062         struct node *body;      /* body expression */
00063         struct op *tag;         /* a type */
00064         struct namenode *space; /* local name space */
00065         short size;             /* number of label names in rule */
00066         short verbose;          /* trace */
00067         } RULE, *RULE_PTR;
00068 
00069 typedef struct snode {          /* stack nodes */
00070         struct snode *next;     /* next node in stack */
00071         short info;
00072         struct node *node;      /* expression tree */
00073         } SNODE;
00074 
00075 /* Definitions of different kinds of operators */
00076 
00077 /* operators (including types) */
00078 typedef struct op {
00079         struct op *next;                /* next node in op table */
00080         short arity;                    /* and associativity */
00081         short precedence;
00082         short eval;                     /* parser reduce function or */
00083                                         /* builtin operator */
00084         struct rule *hash;              /* rules this operator is root of */
00085         struct op *super;               /* supertype */
00086         struct op *other;               /* friend operator */
00087         unsigned char length;           /* length of print name */
00088         char pname[1];                  /* first char of print name */
00089         /* other characters follow ... */
00090         } OP, *OP_PTR;
00091 
00092 /* arity encodes arity, associativity, and other information */
00093 /* other is matching outfix operator, or other operator with same name */
00094 
00095 /* If any of the top 4 bits are on, then this operator is for a TERM_NODE */
00096 /* and the top 4 bits encode arity (number of arguments): */
00097 #define OP_TERM         0xf000  /* this node is a TERM_NODE */
00098 #define NULLARY         0x1000  /* no arguments */
00099 #define UNARY           0x2000  /* one argument */
00100 #define BINARY          0x4000  /* two arguments */
00101 #define ARB             0x8000  /* number of arguments unknown */
00102 
00103 /* The next four bits encode operators for other kinds of nodes */
00104 #define OP_NAME         0x0800  /* for a NAME_NODE */
00105 #define OP_NUM          0x0400  /* for a NUM_NODE */
00106 #define OP_STR          0x0200  /* for a STR_NODE */
00107 
00108 /* The remaining 8 bits encode different things depending upon the arity. */
00109 /* If arity is BINARY: */
00110 #define RIGHT           0x4001  /* binary right associative */
00111 #define LEFT            0x4002  /* binary left associative */
00112 #define NONASSOC        0x4004  /* binary non-associative */
00113 
00114 /* If arity is UNARY: */
00115 #define PREFIX          0x2001  /* unary prefix */
00116 #define POSTFIX         0x2002  /* unary postfix */
00117 #define OUTFIX1         0x2004  /* starting outfix (matchfix) */
00118 #define OUTFIX2         0x2008  /* finishing outfix (matchfix) */
00119 
00120 /* Nodes that live in expressions (shouldn't stow thrones) */
00121 
00122 /* expression term node */
00123 typedef struct termnode {
00124         struct op *op;          /* operator description */
00125         struct namenode *label; /* optional label for node */
00126         struct node *right;     /* right child (optional) */
00127         struct node *left;      /* left child (optional) */
00128         } TERM_NODE, *TERM_NODE_PTR;
00129 
00130 /* name node */
00131 typedef struct namenode {
00132         struct op *op;           /* type of name */
00133         struct namenode *next;   /* next child of parent */
00134         struct namenode *parent; /* back pointer to parent */
00135         struct namenode *child;  /* children of this name */
00136         char *pval;              /* print value of name */
00137         struct node *value;      /* also used during instantiation */
00138         short refs;              /* reference count for garbage collection */
00139         short interest;          /* how interesting is this variable? */
00140         } NAME_NODE, *NAME_NODE_PTR;
00141 
00142 /* numeric constant node */
00143 typedef struct numbernode {
00144         struct op *op;          /* number operator */
00145         double  value;          /* value of number */
00146         } NUM_NODE, *NUM_NODE_PTR;
00147 
00148 /* string node */
00149 typedef struct stringnode {
00150         struct op *op;          /* string operator */
00151         char    *value;         /* actual string */
00152         } STR_NODE, *STR_NODE_PTR;
00153 
00154 /* this union is used only to determine the maximum size of a node */
00155 union maxnode {
00156         struct termnode t;
00157         struct namenode n;
00158         struct numbernode c;
00159         struct stringnode s;
00160         };
00161 
00162 /* Generic expression tree node. Used only for storage management */
00163 /* Will actually be a TERM_NODE, NAME_NODE, NUM_NODE or STR_NODE */
00164 typedef struct node {
00165         struct op *op;          /* operator description */
00166         struct node *next;      /* free list pointer */
00167         /* pad to max size of any node */
00168         char filler[sizeof(union maxnode) -
00169             (sizeof(struct op *) + sizeof(struct node *))];
00170         } NODE, *NODE_PTR;

Generated on Fri Jan 25 09:58:42 2008 for Bertrand by  doxygen 1.5.4