/************************************************************************
 *                    error.c                                           *
 ************************************************************************/
/*     Compile Time error & warning routines for BASCY                  *
 ************************************************************************
 *   Part of the project : BASCY  Version 1.0                           *
 *   Copyright (C) 2001 - S. Narasimhan, No.11, Sathya Nagar,           *
 *                        MADURAI-625018. INDIA                         *
 *                       email: narasimhan_s_@hotmail.com               *
 ************************************************************************
 * This program is free software; you can redistribute it and/or modify *
 * it under the terms of the GNU General Public License as published by *
 * the Free Software Foundation; either version 2 of the License, or    *
 * (at your option) any later version.                                  *
 *                                                                      *
 * This program is distributed in the hope that it will be useful,      *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
 * GNU General Public License for more details.                         *
 *                                                                      *
 * You should have received a copy of the GNU General Public License    *
 * along with this program; if not, write to the Free Software          *
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
 *                                                                      *
 ************************************************************************/
#include <stdio.h>
extern unsigned int errcount,wrncount, lincount;
extern char word[];
void error(int n)
/* prints an error message corresponding to the error number -n
 * Error counter - errcount is also incremented */
{
	errcount++;
        if(word[0] == '\n' || word[0] == '\r')
           strcpy(word,"<END-OF-LINE>");
        fprintf(stderr, "\nLine-%d:Error:",lincount);
	switch(n) {
                case  2 : fprintf(stderr,"Invalid symbol(%s)", word);
			  break;
                case 12 : fprintf(stderr, "%s",word);
                          break;
                case 13 : fprintf(stderr, "Type Mismatch near %s",word);
			  break;
                case 24 : fprintf(stderr,"This builtin is yet to be implemented");
                          break;
                case 201 : fprintf(stderr, "READ/RESTORE without DATA");
                           break;
                case 202 : fprintf(stderr, "Block IF without END IF");
                           break;
                case 203 : fprintf(stderr, "Features not supported for your version are used");
                           break;
                case 204 : fprintf(stderr, "END IF without IF");
                           break;
                case 205 : fprintf(stderr, "%s should occur first in line",word);
                           break;
                case 206 : fprintf(stderr, "ELSE without IF");
                           break;
                case 207 : fprintf(stderr, "')' required near %s", word);
                           break;
                case 208 : fprintf(stderr, "'(' required near %s", word);
                           break;
                case 209 : fprintf(stderr, "%s - Wrong number of dimensions",word);
                           break;
                case 210 : fprintf(stderr, "DIM statement - Max. dimensions exceeded");
                           break;
                case 211 : fprintf(stderr, "Invalid subscript in DIM statement");
                           break;
                case 212 : fprintf(stderr, "Fractions illegal in DIM statement");
                           break;
                case 213 : fprintf(stderr, "Invalid Format String");
                           break;
                case 214 : fprintf(stderr, "Too Many Arguments");
                           break;
		case 215 : fprintf(stderr, "%s-Duplicate Definition",word);
                           break;
                case 216 : fprintf(stderr, "VAR. illegal in DIM statement");
                           break;
                case 217 : fprintf(stderr, "%s: Argument Count Mismatch",word);
                           break;
                case 218 : fprintf(stderr, "EXIT FOR not within FOR ... NEXT");
                           break;
                case 219 : fprintf(stderr, "EXIT DO not within DO ... LOOP");
                           break;
                case 220 : fprintf(stderr, "DO without LOOP");
                           break;
                case 221 : fprintf(stderr, "LOOP without DO");
                           break;
                case 222 : fprintf(stderr, "Library File LIB.DAT corrupted");
                           break;
                case 223 : fprintf(stderr, "Loop nested too deeply");
                           break;
                case 224 : fprintf(stderr, "WEND without WHILE");
                           break;
                case 225 : fprintf(stderr, "WHILE without WEND");
                           break;
                case 226 : fprintf(stderr, "Illegal operator in expression");
                           break;
                case 227 : fprintf(stderr, "Domain Error");
                           break;
                case 228 : fprintf(stderr, "Division by zero");
                           break;
                case 229 : fprintf(stderr, "Internal Error");
                           break;
                case 230 : fprintf(stderr, "Expression too complex");
                           break;
                case 231 : fprintf(stderr,"Label of GOTO referred in GOSUB statement");
                           break;
                case 232 : fprintf(stderr, "Expression incomplete");
                           break;
                case 233 : fprintf(stderr, "Index variable already in use");
                           break;
                case 234 : fprintf(stderr, "NEXT without FOR");
                           break;
                case 235 : fprintf(stderr, "FOR without NEXT");
                           break;
                case 236 : fprintf(stderr, " , Missing near %s", word);
                           break;
                case 237 : fprintf(stderr, "Invalid Builtin Function");
                           break;
                case 238 : fprintf(stderr, "Mismatch in ( and )");
                           break;
                case 239 : fprintf(stderr, "Illegal operator in String Expression");
                           break;
                case 240 : fprintf(stderr, "KEYWORD Missing near %s", word);
                           break;
                case 241 : fprintf(stderr, "Expected proper SEPARATOR");
                           break;
                case 242 : fprintf(stderr, "Expected VARIABLE near %s",word);
                           break;
                case 243 : fprintf(stderr, "Expected assignment operator '=' near %s",word);
                           break;
                case 244 : fprintf(stderr, "Label not defined -> %s", word);
                           break;
                case 245 : fprintf(stderr, "Label Expected");
                           break;
                case 246 : fprintf(stderr, "Statement Expected near %s", word);
                           break;
                case 247 : fprintf(stderr, "Duplicate Label");
			   break;
                case 248 : fprintf(stderr, "Symbol Table Full");
			   break;
                case 249 : fprintf(stderr, "Out of memory");
			   break;
                case 250 : fprintf(stderr, "Syntax Error");
			   break;
                case 251 : fprintf(stderr, "End of statement expected near %s",word);
			   break;
                case 252 : fprintf(stderr, "Expression Expected near %s",word);
			   break;
                case 253 : fprintf(stderr,"Missing string delimiter \"");
			   break;
                case 254 : fprintf(stderr,"String Too Long");
			   break;
                case 255 : fprintf(stderr,"Token/Identifier Too Large");
			   break;
	}
}
void warning(char *msg)
/*prints a warning message (warning is only a diagnostic and not error)
 *warning counter - wrncount is also incremented*/
{
     wrncount++;
     fprintf(stderr,"\nLine-%d:", lincount);
     fprintf(stderr, "Warning : %s -> %s", msg, word);
}
