/home/coin/DyLP-1.1.1/DyLP/src/DylpStdLib/dylib_bnfrdr.h

Go to the documentation of this file.
00001 #ifndef _DYLIB_BNFRDR_H
00002 #define _DYLIB_BNFRDR_H
00003 
00004 /*
00005   This file is part of the support library  for the OsiDylp LP distribution.
00006 
00007         Copyright (C) 2005 Lou Hafer
00008 
00009         School of Computing Science
00010         Simon Fraser University
00011         Burnaby, B.C., V5A 1S6, Canada
00012         lou@cs.sfu.ca
00013 
00014   This program is free software; you can redistribute it and/or modify it
00015   under the terms of the GNU General Public License as published by the Free
00016   Software Foundation; either version 2 of the License, or (at your option)
00017   any later version.
00018 
00019   This program is distributed in the hope that it will be useful, but WITHOUT
00020   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00021   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00022   more details.
00023 
00024   You should have received a copy of the GNU General Public License along
00025   with this program; if not, write to the Free Software Foundation, Inc.,
00026   51 Franklin St., Fifth Floor, Boston, MA  02110-1301  USA
00027 */
00028 
00029 #include "dylib_io.h"
00030 
00031 /*
00032   sccs: @(#)bnfrdr.h    3.5     09/01/99
00033   svn/cvs: "$Id: dylib_bnfrdr.h 71 2006-06-09 04:21:15Z andreasw $" ;
00034 
00035   This file contains the structure definitions required to use the bnf reader
00036   package. The bnf reader depends heavily on the following two assumptions:
00037 
00038   * There is some pointer type into which any other pointer can be cast and
00039     recovered.
00040   
00041   * An int can be cast into a pointer and recovered. This is used to prevent
00042     the complexity of the bnf data structure from getting out of hand, but
00043     could be avoided at the expense of a substantial increase in its size and
00044     awkwardness of use.
00045 
00046   The basic scheme is something like this. At the bottom, we have a number of
00047   terminal constructs: immediates, literals, terminals, and labels of various
00048   flavours. Above these are the three non-terminal constructs: primitives,
00049   non-primitives, and generators. The non-terminals have bodies which are made
00050   up of references to other terminal or non-terminal constructs. Generator
00051   bodies have only one parse; primitive and non-primitive bodies can have a
00052   number of alternative parses. A picture is probably in order here:
00053 
00054   definition      body
00055 
00056   ----------      ----------      ----------      ----------
00057   |        | ---> |        | ---> |  ref   | ---> |  defn  |
00058   ----------      ----------      ----------      ----------
00059                   |  ....  |
00060                   ----------      ----------      ----------
00061                   |        | ---> |  ref   | ---> |  defn  |
00062                   ----------      ----------      ----------
00063 
00064   A definition contains a pointer to its body, which is an array of pointers to
00065   references. Each reference points to a definition. Essentially, a reference
00066   specifies how the second definition is to be used in the context of the body
00067   of the first definition.
00068 
00069   The bnf reader has the capability to create arbitrary links in the data
00070   structure it's building. Some terminology will make things easier:
00071 
00072                 |  ....  |
00073                 ----------      ----------
00074       socket -->| label -+----->|        |
00075                 ----------      ----------
00076                 |  ....  |      |  ....  |
00077 
00078   The value of a label is the address of something. To make a link, the
00079   value of the label has to be stored.  The place where it is stored is
00080   called a socket. The value of a socket is the address of the field where
00081   the value of the label is stored. When it defines a socket, the bnf reader
00082   associates a name with an address; similarly for a label. Both socket and
00083   label references cause a label to be stored in a socket; the difference
00084   between the two lies in which of the socket or label can be undefined when
00085   the reference is processed.
00086 
00087   When it's not important to distinguish between sockets and labels, the
00088   documentation uses label to include both.
00089   
00090   To write a bnf, you use the set of macros defined at the end of
00091   the file. For a detailed explanation of the sorts of things that can be
00092   specified with the bnf, the user should take a look at the supplementary
00093   documentation. The structures and code will make a lot more sense afterward.
00094 */
00095 
00096 
00097 
00098 /*
00099   Definitions of enum types used as codes in the bnf structures which follow.
00100 */
00101 
00102 /*
00103   bnftype_enum codes the type of the bnf definition.
00104 
00105   Value         Description
00106   -----         -----------
00107   bnfG          Generator definition
00108   bnfNP         Non-primitive definition
00109   bnfP          Primitive definition
00110   bnfT          Terminal definition
00111   bnfDS         Socket definition definition
00112   bnfDL         Label definition definition
00113   bnfRS         Socket reference definition 
00114   bnfRL         Label reference definition
00115   bnfI          Immediate value definition
00116   bnfL          Literal definition
00117 */
00118 
00119 typedef enum {bnfG,bnfNP,bnfP,bnfT,bnfDS,
00120               bnfDL,bnfRS,bnfRL,bnfI,bnfL} bnftype_enum ;
00121 
00122 
00123 /*
00124   bnfttype_enum codes the type of lexeme expected by a terminal.
00125 
00126   Value         Description
00127   -----         -----------
00128   bnfttNIL      the null lexeme
00129   bnfttN        number
00130   bnfttID       identifier
00131   bnfttD        delimiter
00132   bnfttF        fixed-length string
00133   bnfttQ        quoted string
00134 */
00135 
00136 typedef enum {bnfttNIL,bnfttN,bnfttID,bnfttD,bnfttF,bnfttQ} bnfttype_enum ;
00137 
00138 
00139 /*
00140   bnflblsrc_enum codes the way in which text strings used for label names
00141   are obtained.
00142 
00143   Value         Description
00144   -----         -----------
00145   bnfncBNF      A bnf is supplied which will produce a text string. If this
00146                 code appears in the context of a name, the string will be the
00147                 name of the label. If it appears in the context of a value,
00148                 the string will be used as a label name and the value
00149                 associated with the name will become the value of the label
00150                 being defined.
00151   bnfncS        An index in the saved text array is supplied. The string
00152                 retrieved is interpreted as for bnfncBNF.
00153   bnfncC        The value of curnde is used as the socket/label value. This
00154                 code is not valid in the context of a name.
00155   bnfncN        The value of newnde is used as the socket/label value. This
00156                 code is not valid in the context of a name.
00157 */
00158 
00159 typedef enum {bnfncBNF,bnfncS,bnfncC,bnfncN} bnflblsrc_enum ;
00160 
00161 
00162 
00163 /*
00164   Flag definitions used in bnf definitions.
00165 
00166   Flag          Description
00167   ----          -----------
00168   bnfadv        Indicates the redefinition of a previously defined label. The
00169                 usual context for use is to redefine (advance) a label which
00170                 is the link in a linked list.
00171   bnfsvnd       Save the text string developed by the nd part of a label
00172                 definition definition or label reference definition.
00173   bnfsvnm       Save the text string developed by the nm part of a label
00174                 definition definition or label reference definition. This
00175                 flag is also used in literal definitions to indicate that text
00176                 should be retrieved from the saved text array.
00177 */
00178 
00179 #define bnfadv  1<<0
00180 #define bnfsvnd 1<<1
00181 #define bnfsvnm 1<<2
00182 
00183 
00184 /*
00185   Flag definitions used in bnf references.
00186 
00187   Flag          Description
00188   ----          -----------
00189   bnflst        The definition referenced describes one element of a list of
00190                 indefinite length.
00191   bnfstore      The value produced by the referenced bnf will be stored
00192                 somehow, and the offset field should be valid.
00193   bnfatsgn      Store a pointer to the character string produced by the
00194                 referenced bnf, rather than the string itself.
00195   bnfstbg       The bnf referenced as the separator between list elements is
00196                 really the beginning of the next list element. (Hence we'll
00197                 have to back up over it once we recognize it.)
00198   bnfflt        A float number is expected here.
00199   bnfdbl        A double number is expected here.
00200   bnfcs         Forces a case-sensitive comparison of the string read for a
00201                 terminal with the value specified in the terminal definition.
00202   bnfmin        Requests a minimum-length comparison - as long as the string
00203                 parsed for the terminal matches the value specified in the
00204                 terminal definition up to the end of the parsed string, the
00205                 comparison succeeds.
00206   bnfsv         Used in primitives to indicate that the string is to be stored
00207                 in the savedtxt array. The offset should be a valid savedtxt
00208                 index in this case.
00209   bnfexact      (bnfttF only) used to prevent the addition of the null
00210                 terminator at the end of a character string when the string
00211                 is stored directly in a field (must be specified to store a
00212                 single char in a field of size sizeof(char))
00213   bnfdebug      Debugging should be activated for this reference and all
00214                 bnf rules nested within it.
00215 */
00216 
00217 #define bnflst          1<<0
00218 #define bnfstore        1<<1
00219 #define bnfatsgn        1<<2
00220 #define bnfstbg         1<<3
00221 #define bnfflt          1<<4
00222 #define bnfcs           1<<5
00223 #define bnfmin          1<<6
00224 #define bnfsv           1<<7
00225 #define bnfexact        1<<8
00226 #define bnfdebug        1<<9
00227 #define bnfdbl          1<<10
00228 
00229 
00230 
00231 /*
00232   Data structures used for bnf definitions. There are three types of things
00233   here: individual structures for the various definition types, a common
00234   structure which consists only of the fields common to all of the individual
00235   structures, and a pointer union which is handy when walking around in a bnf.
00236 
00237   Just to keep the explanation in hand a bit, let's define components and
00238   alternatives. The body of a bnf definition consists of alternatives
00239   (alternative parses), each of which has a number of components. A component
00240   array is an array of pointers to bnf reference structures, each of which in
00241   turn references a bnf definition structure. An alternative array is an array
00242   of pointers to component arrays. I know this is ugly and involves a lot of
00243   dereferencing but it seems to be the only way to handle the variable lengths
00244   involved. 
00245 
00246   NOTE: To keep things from getting completely out of hand, the first entry in
00247         a component or alternative array specifies the number of pointers that
00248         follow. This is one of the (ab)uses of the int - pointer - int cast.
00249 */
00250 
00251 /*
00252   The common portion.
00253 
00254   Field         Description
00255   -----         -----------
00256   type          Type code identifying what sort of definition this is.
00257   name          The name of the rule (derived from the C variable name;
00258                 see the macros gdef, npdef, etc.)
00259 */
00260 
00261 #define bnfdef_common bnftype_enum type ; \
00262                       const char *name ;
00263 
00264 typedef struct { bnfdef_common } bnfdef_struct ;
00265 
00266 
00267 /*
00268   Data structure for a generator definition. Generators cause the creation of a
00269   node in the data structure being built for the user. For simplicity, they may
00270   not have alternative parses, but since they can reference non-primitives no
00271   flexibility is lost.
00272 
00273   Field         Description
00274   -----         -----------
00275   bnfdef_common As above.
00276   size          Size (in bytes) of the node to be created.
00277   link          Offset (in bytes) from the base of the node created by the
00278                 generator to the field used as a link field when this node is
00279                 in a linked list.
00280   comps         Pointer to a component array.
00281 */
00282 
00283 typedef struct { bnfdef_common
00284                  int size ;
00285                  int link ;
00286                  struct bnfref_struct_tag **comps ; } bnfGdef_struct ;
00287 
00288 
00289 /*
00290   Data structure for a non-primitive definition. Non-primitives are simply a
00291   device for defining alternative parses. They don't directly create anything.
00292 
00293   Field         Description
00294   -----         -----------
00295   bnfdef_common As above.
00296   alts          Pointer to an alternative array.
00297 */
00298 
00299 typedef struct {bnfdef_common
00300                 struct bnfref_struct_tag ***alts ; } bnfNPdef_struct ;
00301                 
00302 
00303 
00304 /*
00305   Data structure for a primitive definition. The distinction between a
00306   primitive and a non-primitive is that a primitive constructs a string which
00307   is the concatenation of the strings returned by the bnf's referenced in the
00308   primitive's body. The data structure is identical to that for non-primitives.
00309 */
00310 
00311 typedef bnfNPdef_struct bnfPdef_struct ;
00312 
00313 
00314 /*
00315   Data structure for a terminal. Terminals are used to specify specific things
00316   to be obtained from the input stream. The various parameters required to
00317   describe a terminal should really be mushed into a union, but then the bnf
00318   data structure would have to be built dynamically, since unions can't be
00319   initialized.
00320 
00321   Field         Description
00322   -----         -----------
00323   bnfdef_common As above.
00324   ttype         Code identifying the type of terminal to be obtained.
00325   qschr         Starting character for a quoted string.
00326   qechr         Ending character for a quoted string.
00327   parm1         Overloaded field, interpreted as follows:
00328                 numbers: specifies the radix
00329                 fixed-length strings: specifies the string length
00330   val           Expected value of the string obtained from the input stream.
00331                 (This test is applied before the string is converted to the
00332                  internal form appropriate for whatever is specified in ttype.)
00333 */
00334 
00335 typedef struct { bnfdef_common
00336                  bnfttype_enum ttype ;
00337                  char qschr ;
00338                  char qechr ;
00339                  int parm1 ;
00340                  const char *val ; } bnfTdef_struct ;
00341 
00342 
00343 /*
00344   Data structure for an immediate value. Immediates are used to jam a code into
00345   the data structure being built.
00346 
00347   Field         Description
00348   -----         -----------
00349   bnfdef_common As above.
00350   ival          Integer value.
00351 */
00352 
00353 typedef struct {bnfdef_common
00354                 int ival ; } bnfIdef_struct ;
00355 
00356 
00357 /*
00358   Data structure for a literal. Literals are used to insert characters into the
00359   input stream. (Handy for generating label names, for instance.)
00360 
00361   Field         Description
00362   -----         -----------
00363   bnfdef_common As above.
00364   dflgs         Flags.
00365   txt           The string to be inserted. This field is also used to index
00366                 into the saved text array by casting it to an int.
00367 */
00368 
00369 typedef struct { bnfdef_common
00370                  flags dflgs ;
00371                  char *txt ; } bnfLdef_struct ;
00372 
00373 
00374 /*
00375   Last but not least, the data structure used to define socket/label
00376   definitions and references. (Definitions, mind you - there is another
00377   structure to reference socket/label definitions and references.) A
00378   socket/label definition associates of a name (a text string) with a value
00379   (almost always an address).  A socket/label reference specifies a socket
00380   and a label. The label is inserted into the socket. Fields prefixed by nm
00381   are the name in a socket/label definition and the socket in a socket/label
00382   reference. Fields prefixed by nd are the value in a socket/label definition
00383   and the label in a socket/label reference.
00384 
00385   Field         Description
00386   -----         -----------
00387   bnfdef_common As above.
00388   dflgs         Flags.
00389   nmcd          Specifies how name/socket will be obtained.
00390   ndcd          Specifies how value/label will be obtained.
00391   savnm         Specifies location in saved text array where string associated
00392                 with nm will be stored.
00393   nmsrc         Pointer to bnf which will produce string for nm, or cast into
00394                 an int and used as a location in the saved text array.
00395   savnd         Specifies location in saved text array where string associated
00396                 with nd will be stored.
00397   ndsrc         Pointer to bnf which will produce string for nd, or cast into
00398                 an int and used as a location in the saved text array.
00399   offset        Correction (in bytes) to socket/label value (socket/label
00400                 definitions) or socket (socket/label references).
00401   offset2       Correction (in bytes) to label (socket/label references).
00402 */
00403 
00404 typedef struct { bnfdef_common
00405                  flags dflgs ;
00406                  bnflblsrc_enum nmcd ;
00407                  bnflblsrc_enum ndcd ;
00408                  int savnm ;
00409                  struct bnfref_struct_tag *nmsrc ;
00410                  int savnd ;
00411                  struct bnfref_struct_tag *ndsrc ;
00412                  int offset ;
00413                  int offset2 ; } bnfLBdef_struct ;
00414 
00415 
00416 /*
00417   And finally, the handy union of pointers promised back at the start. We
00418   really should be using this in the bnf reference structure declarations,
00419   rather than (bnfdef_struct *), but since references and definitions are
00420   mutually recursive we get into ugliness. There's also the point that we
00421   want to be able to create bnfs at compile time and you can't initialize
00422   unions.
00423 */
00424 
00425 typedef union { bnfdef_struct *com ;
00426                 bnfGdef_struct *G ;
00427                 bnfNPdef_struct *NP ;
00428                 bnfPdef_struct *P ;
00429                 bnfTdef_struct *T ;
00430                 bnfIdef_struct *I ;
00431                 bnfLdef_struct *L ;
00432                 bnfLBdef_struct *LB ; } bnfdef_any ;
00433 
00434 
00435 
00436 /*
00437   Now, on to the data structures used to reference bnf definitions. Recall if
00438   you will the introductory comments about component and alternative arrays and
00439   the general setup of the bnf data structure. We have the same three types of
00440   data structures here as for bnf definitions.
00441 */
00442 
00443 /*
00444   The common portion. It includes a type code, a name, usage flags, and a
00445   pointer to the bnf definition.
00446 
00447   Field         Description
00448   -----         -----------
00449   type          Type code identifying what sort of definition this reference
00450                 points to.
00451   name          The name of the reference (derived from the C variable name;
00452                 see the macros qref, npref, pref, etc.)
00453   uflgs         Usage flags.
00454   defn          Pointer to a bnf definition structure.
00455 */
00456 
00457 #define bnfref_common bnftype_enum type ; \
00458                       const char *name ; \
00459                       bnfdef_struct *defn ; \
00460                       flags uflgs ;
00461 
00462 typedef struct bnfref_struct_tag { bnfref_common } bnfref_struct ;
00463 
00464 
00465 /*
00466   References to labels of all flavours and to literals require only the
00467   common fields. The only reason we need the uflgs field is for the bnfdebug
00468   flag.
00469 */
00470 
00471 typedef bnfref_struct bnfLBref_struct ;
00472 typedef bnfref_struct bnfLref_struct ;
00473 
00474 
00475 /*
00476   References to terminals and immediates require an offset for storage.
00477 
00478   Field         Description
00479   -----         -----------
00480   bnfref_common As above.
00481   offset        Offset (in bytes) into current node to the field where the
00482                 value produced by the referenced bnf will be stored.
00483 */
00484 
00485 struct bnfref_type2 { bnfref_common
00486                       int offset ; } ;
00487 
00488 typedef struct bnfref_type2 bnfTref_struct ;
00489 typedef struct bnfref_type2 bnfIref_struct ;
00490 
00491 
00492 /*
00493   References to generators, non-primitives, and primitives can be in lists and
00494   require a separator specification in addition to the offset. Non-primitives
00495   do not make use of the offset field.
00496 
00497   Field         Description
00498   -----         -----------
00499   bnfref_common As above.
00500   offset        Offset (in bytes) into current node to the field where the
00501                 value produced by the referenced bnf will be stored.
00502   sep           A reference to a bnf definition describing the separator
00503                 between list elements in the input stream.
00504 */
00505 
00506 struct bnfref_type3 { bnfref_common
00507                       int offset ;
00508                       bnfref_struct *sep ; } ;
00509 
00510 typedef struct bnfref_type3 bnfGref_struct ;
00511 typedef struct bnfref_type3 bnfNPref_struct ;
00512 typedef struct bnfref_type3 bnfPref_struct ;
00513 
00514 
00515 /*
00516   And the handy union pointer type. Same general comments as for the
00517   declaration of bnfdef_any.
00518 */
00519 
00520 typedef union { bnfref_struct *com ;
00521                 struct bnfref_type1 *t1 ;
00522                 struct bnfref_type2 *t2 ;
00523                 struct bnfref_type3 *t3 ;
00524                 bnfGref_struct *G ;
00525                 bnfNPref_struct *NP ;
00526                 bnfPref_struct *P ;
00527                 bnfTref_struct *T ;
00528                 bnfIref_struct *I ;
00529                 bnfLref_struct *L ;
00530                 bnfLBref_struct *LB ; } bnfref_any ;
00531 
00532 
00533 
00534 /*
00535   The macros that make defining the bnf data structures marginally
00536   less painful.
00537 */
00538 
00539 /*
00540   Macros to help with constructing field offsets. NULLP is specially designed
00541   to produce a NULL value when used as &NULLP. This is required for some of the
00542   macros where one must fill the field with either the address of a
00543   bnfref_struct or the value NULL. By this device we avoid having to make the
00544   user aware of when and when not to use &. mkoff simply produces the offset of
00545   a given field in a structure type.
00546 */
00547 
00548 #define NULLP (*((char *) 0))
00549 #define mksav(qqoff) (*((char *) qqoff))
00550 #define mkoff(qqtype,qqfield) (&((qqtype *) 0)->qqfield)
00551 
00552 /*
00553   Macros for alternative and component lists. These just generate the headers;
00554   the actual lists have to be typed out, as:
00555 
00556   althd(arule_alts) = { altcnt(3),
00557                         mkaref(arule_alt1), mkaref(arule_alt2),
00558                         mkaref(arule_alt3) } ;
00559 
00560   comphd(arule_alt1) = { compcnt(2),
00561                          mkcref(brule_ref), mkcref(crule_ref) } ;
00562 
00563   where brule_ref and crule_ref are bnf references (most likely constructed
00564   using the gref, npref, etc. macros).
00565 */
00566 
00567 #define althd(qqnme) bnfref_struct **qqnme[]
00568 #define altcnt(qqcnt) (bnfref_struct **) (qqcnt)
00569 #define mkaref(qqref) (bnfref_struct **) (qqref)
00570 
00571 #define comphd(qqnme) bnfref_struct *qqnme[]
00572 #define compcnt(qqcnt) (bnfref_struct *) (qqcnt)
00573 #define mkcref(qqref) (bnfref_struct *) (&qqref)
00574 
00575 /*
00576   Macros to initialise bnf definitions. Note the use of the ANSI C
00577   'stringisation' operator, '#', to get a text string for the name. For
00578   non-ANSI implementations, replacing #qqnme with "qqnme" usually works (but
00579   not all non-ANSI preprocessor implementations will see the macro parameter
00580   inside a string, and ANSI C explicitly disallows it).
00581 */
00582 
00583 #define gdef(qqnme,qqsze,qqlnk,qqcomps) \
00584 bnfGdef_struct qqnme = { bnfG, #qqnme, (int) (qqsze), (int) (qqlnk), \
00585                          (bnfref_struct **) qqcomps }
00586 
00587 #define npdef(qqnme,qqalts) \
00588 bnfNPdef_struct qqnme = { bnfNP, #qqnme, (bnfref_struct ***) qqalts }
00589 
00590 #define pdef(qqnme,qqalts) \
00591 bnfPdef_struct qqnme = { bnfP, #qqnme, (bnfref_struct ***) qqalts }
00592 
00593 #define tdef(qqnme,qqttype,qqparm,qqval) \
00594 bnfTdef_struct qqnme = { bnfT, #qqnme, qqttype, '\0', '\0', \
00595                          (int) (qqparm), (const char *) (qqval) }
00596 
00597 #define tqdef(qqnme,qqschr,qqechr,qqval) \
00598 bnfTdef_struct qqnme = { bnfT, #qqnme, bnfttQ, (char) qqschr, (char) qqechr,\
00599                          0, (char *) (qqval) }
00600 
00601 #define dfdef(qqnme,qqdflgs,qqnmcd,qqnm,qqsavnm,qqndcd,qqnd,qqsavnd,qqoff) \
00602 bnfLBdef_struct qqnme = { bnfDS, #qqnme, (flags) (qqdflgs), qqnmcd, qqndcd, \
00603                           (int) (qqsavnm), (bnfref_struct *) &qqnm, \
00604                           (int) (qqsavnd), (bnfref_struct *) &qqnd, \
00605                           (int) (qqoff), 0 }
00606 
00607 #define dbdef(qqnme,qqdflgs,qqnmcd,qqnm,qqsavnm,qqndcd,qqnd,qqsavnd,qqoff) \
00608 bnfLBdef_struct qqnme = { bnfDL, #qqnme, (flags) (qqdflgs), qqnmcd, qqndcd, \
00609                           (int) (qqsavnm), (bnfref_struct *) &qqnm, \
00610                           (int) (qqsavnd), (bnfref_struct *) &qqnd, \
00611                           (int) (qqoff), 0 }
00612 
00613 #define rfdef(qqnme,qqdflgs,qqnmcd,qqnm,qqsavnm,qqoff,qqndcd,qqnd,qqsavnd,qqoff2) \
00614 bnfLBdef_struct qqnme = { bnfRS, #qqnme, (flags) (qqdflgs), qqnmcd, qqndcd, \
00615                           (int) (qqsavnm), (bnfref_struct *) &qqnm, \
00616                           (int) (qqsavnd), (bnfref_struct *) &qqnd, \
00617                           (int) (qqoff), (int) (qqoff2) }
00618 
00619 #define rbdef(qqnme,qqdflgs,qqnmcd,qqnm,qqsavnm,qqoff,qqndcd,qqnd,qqsavnd,qqoff2) \
00620 bnfLBdef_struct qqnme = { bnfRL, #qqnme, (flags) (qqdflgs), qqnmcd, qqndcd, \
00621                           (int) (qqsavnm), (bnfref_struct *) &qqnm, \
00622                           (int) (qqsavnd), (bnfref_struct *) &qqnd, \
00623                           (int) (qqoff), (int) (qqoff2) }
00624 
00625 #define idef(qqnme,qqval) \
00626 bnfIdef_struct qqnme = { bnfI, #qqnme, (int) (qqval) }
00627 
00628 #define ldef(qqnme,qqdflgs,qqtxt) \
00629 bnfLdef_struct qqnme = { bnfL, #qqnme, (flags) (qqdflgs), (char *) (qqtxt) }
00630 
00631 
00632 
00633 #define gref(qqnme,qqref,qquflgs,qqoff,qqsep) \
00634 bnfGref_struct qqnme = { bnfG, #qqnme, (bnfdef_struct *) &qqref, \
00635                          (flags) (qquflgs), (int) (qqoff), \
00636                          (bnfref_struct *) &qqsep }
00637 
00638 #define npref(qqnme,qqref,qquflgs,qqsep) \
00639 bnfNPref_struct qqnme = { bnfNP, #qqnme, (bnfdef_struct *) &qqref, \
00640                          (flags) (qquflgs), (int) 0, (bnfref_struct *) &qqsep }
00641 
00642 #define pref(qqnme,qqref,qquflgs,qqoff,qqsep) \
00643 bnfPref_struct qqnme = { bnfP, #qqnme, (bnfdef_struct *) &qqref, \
00644                          (flags) (qquflgs), (int) (qqoff), \
00645                          (bnfref_struct *) &qqsep }
00646 
00647 #define tref(qqnme,qqref,qquflgs,qqoff) \
00648 bnfTref_struct qqnme = { bnfT, #qqnme, (bnfdef_struct *) &qqref, \
00649                          (flags) qquflgs, (int) qqoff }
00650 
00651 #define dfref(qqnme,qqref) \
00652 bnfLBref_struct qqnme = { bnfDS, #qqnme, (bnfdef_struct *) &qqref, (flags) 0 }
00653 
00654 #define dbref(qqnme,qqref) \
00655 bnfLBref_struct qqnme = { bnfDL, #qqnme, (bnfdef_struct *) &qqref, (flags) 0 }
00656 
00657 #define rfref(qqnme,qqref) \
00658 bnfLBref_struct qqnme = { bnfRS, #qqnme, (bnfdef_struct *) &qqref, (flags) 0 }
00659 
00660 #define rbref(qqnme,qqref) \
00661 bnfLBref_struct qqnme = { bnfRL, #qqnme, (bnfdef_struct *) &qqref, (flags) 0 }
00662 
00663 #define iref(qqnme,qqref,qqoff) \
00664 bnfIref_struct qqnme = { bnfI, #qqnme, (bnfdef_struct *) &qqref, \
00665                         (flags) 0, (int) qqoff }
00666 
00667 #define lref(qqnme,qqref) \
00668 bnfLref_struct qqnme = { bnfL, #qqnme, (bnfdef_struct *) &qqref, (flags) 0 }
00669 
00670 #ifndef DYLP_NDEBUG
00671 
00672 /*
00673   This set of definitions sets the bnfdebug flag, but doesn't add a separate
00674   uflgs parameter (we don't want to lead the user to think any of the others
00675   are valid).
00676 */
00677 
00678 #define dfrefdbg(qqnme,qqref) \
00679 bnfLBref_struct qqnme = { bnfDS, #qqnme, (bnfdef_struct *) &qqref, \
00680                           (flags) bnfdebug }
00681 
00682 #define dbrefdbg(qqnme,qqref) \
00683 bnfLBref_struct qqnme = { bnfDL, #qqnme, (bnfdef_struct *) &qqref, \
00684                           (flags) bnfdebug }
00685 
00686 #define rfrefdbg(qqnme,qqref) \
00687 bnfLBref_struct qqnme = { bnfRS, #qqnme, (bnfdef_struct *) &qqref, \
00688                           (flags) bnfdebug }
00689 
00690 #define rbrefdbg(qqnme,qqref) \
00691 bnfLBref_struct qqnme = { bnfRL, #qqnme, (bnfdef_struct *) &qqref, \
00692                           (flags) bnfdebug }
00693 
00694 #define lrefdbg(qqnme,qqref) \
00695 bnfLref_struct qqnme = { bnfL, #qqnme, (bnfdef_struct *) &qqref, \
00696                           (flags) bnfdebug }
00697 
00698 #endif /* DYLP_NDEBUG */
00699 
00700 
00701 
00702 /*
00703   Last, but not least, some declarations to allow the use of the bnf reader.
00704   rdrinit and rdrclear initialize and clear the reader; they should bracket
00705   related groups of calls. parse is the main parsing routine. The union type
00706   parse_any is the appropriate thing to hold the result.
00707 */
00708 
00709 typedef union { void *g ;
00710                 char *c ; } parse_any ;
00711 
00712 extern void rdrinit(void),rdrclear(void) ;
00713 extern bool parse(ioid chn, struct bnfref_type3 *bnfid, parse_any *result) ;
00714 
00715 #ifndef DYLP_NDEBUG
00716 /*
00717   The control routine for the bnf debugging trace output. See the comments
00718   in bnfrdr.c for the proper use of the parameters.
00719 */
00720   
00721 extern void bnfdbgctl(ioid dbgchn, bool dbgecho, bool warnzlbl, bool numlvl,
00722                       bool tablvl) ;
00723 #else
00724 #define bnfdbgctl(dgbchn,dbgecho,warnzlbl,numlvl,tablvl)
00725 #endif
00726 
00727 /*
00728   Utility print routines from bnfrdrio.c.
00729 */
00730 
00731 extern void prtbnfref(ioid chn, bool echo, bnfref_struct *ref),
00732             prtbnfdef(ioid chn, bool echo, bnfdef_struct *def) ;
00733 
00734 #endif /* _DYLIB_BNFRDR_H */

Generated on Wed Aug 22 05:45:12 2007 by  doxygen 1.4.7