⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 language.h

📁 COP8 CPU的一个解释型BASIC源码
💻 H
字号:
////////////////////////////////////////////////////////////////
//
//                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   : language.h
// PURPOSE: to initialize the language tables and to 
//          enumerate all possible tokens (the language elements).
//          The table are:
//          the dictionary, that lists the correspondance between 
//          ASCII stringss and token codes and the JUMP TABLE,
//          that lists the functions implementing each token.
//			Instances are in language.c
//
////////////////////////////////////////////////////////////////

#ifndef LANGUAGE_INCLUDED
#define LANGUAGE_INCLUDED

enum { 
	//programming language tokens
	//executable tokens
	//must match function_initializer in order the jump table to work
	END_FILE = 0,
	END_PROGRAM = 129,
	IF,
 	ELSE,
 	END_IF,
	WHILE,
	END_WHILE,
	VARIABLE,
	END_FUNCTION, 
	VARIABLE_NAME,
	FUNCTION_NAME,
	PRINT,
	CLS,
	BOX,
	FUNCTION,
	GET_SERIAL,
	MAX_RUNNABLE,		//only runnable tokens match an executable routine

	//Next tokens are not runnable, and they cause an error if used alone.
	//To be used together with another token or to specify or to separate 
	//(ex. IF --> THEN)
	
	CR = MAX_RUNNABLE,
	AT,
	COMMA,
	COM,
	QUOTE,
	NUMBER,
	ASSIGN,
	THEN,
	PAR_VOID,

	//Math tokens, in order of evaluation priority

	START_EXP,		//lowest precedence, pushed at startup to force evaluation at end
	END_EXP,		//indicates end of expression
    PAR_CLOSE,		LOGIC_OR,		LOGIC_AND,		BITWISE_OR,
    BITWISE_XOR,	BITWISE_AND,	NOT_EQUAL,		EQUAL,
	LESS_EQUAL,		LESS,			GREATER_EQUAL,	GREATER,
	SHIFT_RIGHT,	SHIFT_LEFT,		ADD,			SUB,
    MULT,			DIV,			MOD,			LOGIC_NOT,
    BITWISE_NOT,	
	PAR_OPEN,		//highest precedence
	MAX_TOKENS
};


/*the jump table tells the routine to execute for every runnable token*/
/*order must match the previous enum */
#define jump_table_initializer  {								\
	/*END_FILE,*/		end_program,							\
	/*END_PROGRAM*/		end_program,							\
	/*IF*/				do_if,									\
	/*ELSE*/			do_else,								\
 	/*END_IF*/			do_nothing,								\
	/*WHILE*/			do_while,								\
	/*END_WHILE*/		end_while,								\
	/*VARIABLE*/		variable,								\
	/*END_FUNCTION*/	end_function,							\
	/*VARIABLE_NAME*/	assignment,								\
	/*FUNCTION_NAME*/	function_immediate,						\
	/*PRINT*/			print,									\
	/*CLS*/				LCD_clear_text,							\
	/*BOX*/	    		box,    								\
	/*FUNCTION*/	    end_program,                            \
	/*GET*/             get_serial,                             \
}

/*correspondence between ASCII strings and token - can be in any order*/
/*but for efficiency put most popular first*/
#define dictionary_initializer  {								\
	"IF",		IF,												\
	"THEN",		THEN,											\
	"WHILE",	WHILE,											\
	"WEND",		END_WHILE,										\
	"PRINT",	PRINT,											\
	"@",		AT,												\
	",",		COMMA,											\
	"ENDIF",	END_IF,											\
	"BOX",		BOX,											\
	"CR",		CR,												\
	"ELSE",		ELSE,  											\
	"COM",	    COM,											\
	"VAR",		VARIABLE,										\
	"FUNCTION",	FUNCTION,										\
	"FEND",		END_FUNCTION,									\
	"GET",		GET_SERIAL,    									\
	"CLS",		CLS,											\
	"()",		PAR_VOID,										\
																\
    ")",		PAR_CLOSE,										\
	"||",		LOGIC_OR,										\
	"&&",		LOGIC_AND,										\
	"|",		BITWISE_OR,										\
    "^",		BITWISE_XOR,									\
    "&",		BITWISE_AND,									\
    "!=",		NOT_EQUAL,										\
    "==",		EQUAL,											\
	"=",		ASSIGN,											\
    "<=",		LESS_EQUAL,										\
	">>",		SHIFT_RIGHT,									\
	"<<",		SHIFT_LEFT,										\
    "<",		LESS,											\
    ">=",		GREATER_EQUAL,									\
    ">",		GREATER,										\
    "+",		ADD,											\
    "-",		SUB,											\
    "*",		MULT,											\
    "/",		DIV,											\
    "%",		MOD,											\
    "!",		LOGIC_NOT,										\
    "~",		BITWISE_NOT,									\
    "(",		PAR_OPEN,										\
};

#define DICTIONARY_SIZE  41

typedef struct {      
	unsigned  char __cptr * command;
	unsigned  char token;
} dictionary_t;

extern void (*jump_table[MAX_RUNNABLE - 128])();

extern const dictionary_t     dictionary[DICTIONARY_SIZE];


#endif

⌨️ 快捷键说明

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