Beispiel #1
0
ANTLR_INFO

#include "charptr.c"

int main() {
  ANTLR(expr(), stdin);
}
Beispiel #2
0
/* ------------------------------------------------------------------------
@NAME       : bt_parse_file ()
@INPUT      : filename - name of file to open.  If NULL or "-", we read
                         from stdin rather than opening a new file.
              options
@OUTPUT     : top
@RETURNS    : 0 if any entries in the file had serious errors
              1 if all entries were OK
@DESCRIPTION: Parses an entire BibTeX file, and returns a linked list 
              of ASTs (or, if you like, a forest) for the entries in it.
              (Any entries with serious errors are omitted from the list.)
@GLOBALS    : 
@CALLS      : bt_parse_entry()
@CREATED    : 1997/01/18, from process_file() in bibparse.c
@MODIFIED   : 
@COMMENTS   : This function bears a *striking* resemblance to bibparse.c's
              process_file().  Eventually, I plan to replace this with 
              a generalized process_file() that takes a function pointer
              to call for each entry.  Until I decide on the right interface
              for that, though, I'm sticking with this simpler (but possibly
              memory-intensive) approach.
-------------------------------------------------------------------------- */
AST * bt_parse_file (char *    filename, 
                     ushort    options, 
                     boolean * status)
{
   FILE *  infile;
   AST *   entries,
       *   cur_entry, 
       *   last;
   boolean entry_status,
           overall_status;

   if (options & BTO_STRINGMASK)        /* any string options set? */
   {
      usage_error ("bt_parse_file: illegal options "
                   "(string options not allowed");
   }

   /*
    * If a string was given, and it's *not* "-", then open that filename.
    * Otherwise just use stdin.
    */

   if (filename != NULL && strcmp (filename, "-") != 0)
   {
      InputFilename = filename;
      infile = fopen (filename, "r");
      if (infile == NULL)
      {
         perror (filename);
         return 0;
      }
   }
   else
   {
      InputFilename = "(stdin)";
      infile = stdin;
   }

   entries = NULL;
   last = NULL;
      
#if 1
   /* explicit loop over entries, with junk cleaned out by read_entry () */

   overall_status = TRUE;              /* assume success */
   while ((cur_entry = bt_parse_entry
          (infile, InputFilename, options, &entry_status)))
   {
      overall_status &= entry_status;
      if (!entry_status) continue;      /* bad entry -- try next one */
      if (!cur_entry) break;            /* at eof -- we're done */
      if (last == NULL)                 /* this is the first entry */
         entries = cur_entry;
      else                              /* have already seen one */
         last->right = cur_entry;

      last = cur_entry;
   }

#else
   /* let the PCCTS lexer/parser handle everything */

   initialize_lexer_state ();
   ANTLR (bibfile (top), infile);

#endif

   fclose (infile);
   InputFilename = NULL;
   if (status) *status = overall_status;
   return entries;

} /* bt_parse_file() */