error.cpp

来自「c语言的简化编译器」· C++ 代码 · 共 69 行

CPP
69
字号
/* wig error.c
 *
 * history:
 * 17.10.2000 created, defined yyerror()
 */
#include "stdafx.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "error.h"

extern char *yytext;

int lineno = 0;

int errors = 0;

void yyerror(const char *format, ...)
{
  va_list argList;
  
  va_start(argList, format);
  vfprintf(stderr, format, argList);
  va_end(argList);
  
  fprintf(stderr, "\n");
  fprintf(stderr, "*** syntax error before %s at line %i\n", yytext, lineno);
  fprintf(stderr, "*** compilation terminated\n");
  
  exit(1);
}

void reportError(int lineno, const char *format, ...)
{
  va_list argList;

  fprintf(stderr, "*** Error: ");
  
  va_start(argList, format);
  vfprintf(stderr, format, argList);
  va_end(argList);
  
  fprintf(stderr, " at line %i\n", lineno);

  errors++;
}

void reportWarning(int lineno, const char *format, ...)
{
  va_list argList;

  fprintf(stderr, "*** Warning: ");
  
  va_start(argList, format);
  vfprintf(stderr, format, argList);
  va_end(argList);
  
  fprintf(stderr, " at line %i\n", lineno);
}

void errorCheck()
{
  if (errors!=0) {
  fprintf(stderr, "*** %i error(s) encountered, compilation terminated\n",errors);
     exit(1);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?