errors.h

来自「COP8 CPU的一个解释型BASIC源码」· C头文件 代码 · 共 52 行

H
52
字号
////////////////////////////////////////////////////////////////
//
//                S C R I P T H E R M
//             A SCRIPTABLE THERMOMETER
// 
// entry of the National Semiconductor COP8FLASH Design Contest
//        submitted by Alberto Ricci Bitti (C) 2001
//              a.riccibitti@ra.nettuno.it
//
//--------------------------------------------------------------
//       FOR A BETTER VIEW SET TAB SIZE=4, INDENT SIZE=4
//--------------------------------------------------------------
// FILE   : errors.h
// PURPOSE: prints error message and aborts current task
//          using a setjmp
//          See also the #defines in error.h 
//
////////////////////////////////////////////////////////////////

#ifndef ERRORS_INCLUDED
#define ERRORS_INCLUDED

#include <setjmp.h>

// error messages
//ensure that strings match the type_error enumeration
#define error_messages_initilializer {		\
		"Syntax error",						\
		"Unbalanced parens",				\
		"No expression present",			\
		"Not a variable/procedure",			\
		"Expected: THEN",					\
		"Program too complex",				\
		"Repeat/Ifs unbalanced"				\
		"Too many variables/procedures"		\
		};

typedef enum {	
	SYNTAX_ERROR,		UNBALANCED_PARENS,	NO_EXPRESSION,		EXPECTED_NAME, 
	EXPECTED_THEN,  	NESTING_TOO_DEEP,	NESTING_UNBALANCED, TOO_MANY_NAMES,
} type_error;


#define error_occurred()		setjmp( error_mark )

//issues the specified error if the condition is not met
#define ensure( condition, error )  { if (!(condition)) syntax_error(error); }

extern void syntax_error(type_error error); 

#endif

⌨️ 快捷键说明

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