home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / yyerror.c < prev    next >
C/C++ Source or Header  |  1992-10-19  |  1KB  |  61 lines

  1. /*
  2.  * yyerror.C - error function for parser.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #include <stdlib.h>
  19. #include <stream.h>
  20. #include "yyerror.h"
  21.  
  22. rcString currentFilename;
  23.  
  24. int yyerror(const char* msg)
  25. {
  26.   extern int yynerrs;    
  27.   extern int lineno;   // current line number
  28.   extern char* yytext;          
  29.   char colon = 0;
  30.  
  31.   cerr << "[Error " <<  yynerrs << "] ";
  32.   if (!currentFilename.empty())
  33.     cerr << "File \'" << currentFilename << "\', ";
  34.     
  35.   if (lineno > 0) {
  36.     cerr << "line " << 1+lineno-(*yytext == '\n' || *yytext);
  37.     colon = 1;
  38.   }
  39.   if (*yytext)
  40.   {
  41.     int i;
  42.     for (i = 0; i < 20; ++i)
  43.       if (!yytext[i] || yytext[i] == '\n')
  44.     break;
  45.     if (i > 0)
  46.     {
  47.       if (colon) cerr << " ";
  48.       cerr << "near \"" << form("%.*s\" ", i, yytext);
  49.       colon = 1;
  50.     }
  51.   }
  52.   if (colon)
  53.     cerr << ": ";
  54.   cerr << msg << "!\n";
  55.   cerr.flush();
  56.  
  57.   exit(1);
  58.  
  59.   return 1;
  60. }
  61.